易截截图软件、单文件、免安装、纯绿色、仅160KB
热门标签: c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 最新文章 : xml

xml中特殊符号的转换

调试时发现日志报如下错误 org.xml.sax.SAXParseException
发现是xml对特殊符号要做处理,几个特殊符号如下:
&lt; < 小于号
&gt; > 大于号
&amp; & 和
&apos; ' 单引号
&quot; " 双引号
在xml中把特殊符号用上述转下即好了 ......

C#写XML的简单例子

这个例子要把bookstore.xml文件增加一条book记录
1 bookstore.xml
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
  <book genre="love" ISBN="1234123">
    <title>who am i </title>
    <author>who</author>
    <price>999</price>
  </book>
</bookstore>
2 bookstore.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace toxml
{
    public class ToXml
    {
        public static void Main(string[] args)
        {
            //实例化一个XmlDocument对象
            XmlDocument xmlDoc = new XmlDocument();
            //实例对象读 ......

C#写XML的简单例子

这个例子要把bookstore.xml文件增加一条book记录
1 bookstore.xml
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
  <book genre="love" ISBN="1234123">
    <title>who am i </title>
    <author>who</author>
    <price>999</price>
  </book>
</bookstore>
2 bookstore.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace toxml
{
    public class ToXml
    {
        public static void Main(string[] args)
        {
            //实例化一个XmlDocument对象
            XmlDocument xmlDoc = new XmlDocument();
            //实例对象读 ......

XML 序列化简介

序列化是将对象转换成易于传输的形式的过程。例如,可以序列化对象,并使用 HTTP 通过 Internet 在客户端和服务器之间进行传输。另一方面,反序列化在流中重新构建对象。
XML 序列化只将对象的公共字段和属性值序列化为 XML 流。XML 序列化不包括类型信息。例如,如果 Library 命名空间中存在 Book 对象,则不能保证将它反序列化为同一类型的对象。
注意:
XML 序列化不能转换方法、索引器、私有字段或只读属性(只读集合除外)。要序列化对象的所有公共和私有字段和属性,请使用 BinaryFormatter 而不要使用 XML 序列化。
XML 序列化中的中心类是 XmlSerializer 类,该类中最重要的方法是 Serialize 和 Deserialize 方法。XmlSerializer 创建 C# 文件并将其编译为 .dll 文件,以执行此序列化。
对象中的数据是用编程语言构造来描述的,如类、字段、属性 (Property)、基元类型、数组,甚至 XmlElement 或 XmlAttribute 对象形式的嵌入 XML。可以创建自己的用属性 (Attribute) 批注的类,也可以使用 XML 架构定义工具生成基于现有 XML 架构的类。
如果有 XML 架构,则可以运行 XML 架构定义工具生成一组类,将这组类的类型强制为此架构,并用属性 (Attribute) 进行批注。 ......

XML 序列化示例

XML 序列化可以采用从简单到复杂的多种形式。例如,可以序列化只包含公共字段和公共属性的类,如 XML 序列化简介中所示。下面的代码示例讨论各种高级方案,包括如何使用 XML 序列化生成符合特定 XML 架构 (XSD) 文档的 XML 流。
序列化数据集
除了序列化公共类的实例外,还可序列化 DataSet 的实例,如下面的代码示例所示。
private void SerializeDataSet(string filename){
    XmlSerializer ser = new XmlSerializer(typeof(DataSet));
       
    // Creates a DataSet; adds a table, column, and ten rows.
    DataSet ds = new DataSet("myDataSet");
    DataTable t = new DataTable("table1");
    DataColumn c = new DataColumn("thing");
    t.Columns.Add(c);
    ds.Tables.Add(t);
    DataRow r;
    for(int i = 0; i<10;i++){
        r = t.NewRow();
        r[0] = "Thi ......

C#修改XML的简单例子

接上一篇《C#写XML的简单例子》
这个例子要修改XML文件中结点的属性和和元素的文本
1 原xml文件 bookstore.xml
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
  <book genre="love" ISBN="1234123">
    <title>who am i </title>
    <author>who</author>
    <price>999</price>
  </book>
  <book leixing="music" ISBN="56756">
    <title>CS从入门到精通</title>
    <author>候捷</author>
    <price>222</price>
  </book>
</bookstore>
2 program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
& ......

C#修改XML的简单例子

接上一篇《C#写XML的简单例子》
这个例子要修改XML文件中结点的属性和和元素的文本
1 原xml文件 bookstore.xml
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
  <book genre="love" ISBN="1234123">
    <title>who am i </title>
    <author>who</author>
    <price>999</price>
  </book>
  <book leixing="music" ISBN="56756">
    <title>CS从入门到精通</title>
    <author>候捷</author>
    <price>222</price>
  </book>
</bookstore>
2 program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
& ......

C#删除XML结点的简单例子

接上一篇
删除原genre属性,删除leixing=love的所有结点。
1 原xml文件 bookstore.xml
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
  <book genre="love" ISBN="1234123">
    <title>who am i </title>
    <author>who</author>
    <price>999</price>
  </book>
  <book leixing="love" ISBN="56756">
    <title>CS从入门到精通</title>
    <author>黎明</author>
    <price>222</price>
  </book>
</bookstore>
2 program.cs
using System;
using System.Xml;
namespace ReadXml
{
    class Class1
    {
        static void Main(string[] args)
        {
            //实例化一个XmlDocument对象
    ......

C#删除XML结点的简单例子

接上一篇
删除原genre属性,删除leixing=love的所有结点。
1 原xml文件 bookstore.xml
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
  <book genre="love" ISBN="1234123">
    <title>who am i </title>
    <author>who</author>
    <price>999</price>
  </book>
  <book leixing="love" ISBN="56756">
    <title>CS从入门到精通</title>
    <author>黎明</author>
    <price>222</price>
  </book>
</bookstore>
2 program.cs
using System;
using System.Xml;
namespace ReadXml
{
    class Class1
    {
        static void Main(string[] args)
        {
            //实例化一个XmlDocument对象
    ......
总记录数:815; 总页数:136; 每页6 条; 首页 上一页 [91] [92] [93] [94] 95 [96] [97] [98] [99] [100]  下一页 尾页
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号