博客
关于我
XDocument类
阅读量:362 次
发布时间:2019-03-04

本文共 800 字,大约阅读时间需要 2 分钟。

XDocument类提供了处理XML的方法,包括声明,注释和处理指令,一个XDocument对象可以包括以下内容:
  1.  一个单一XElement对象(根)
  2.  一个单一的XDeclaration对象
  3.  一个单一的XDocumentType对象(指向一个DTD)
  4.  任何数量的XProcessingInstruction对象
  5.  任何数量的XComment对象
不过在LINQ to XML来处理XML时基本不会用到声明,注释和处理指令.
下面就用一个示例来看看如何用XDocument来创建一个简单的XML文档吧,它包含几个元素和一个属性,一个处理指令和一些注释.

 

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace ConsoleApplication1
{
   
class Program
    {
       
static void Main(string[] args)
        {
            XDocument doc
= new XDocument(
               
new XProcessingInstruction("xml-stylesheet", "title='黄聪'"),
               
new XComment("注释1"),
               
new XElement("Root",
                   
new XElement("Persons",
                       
new XElement("Person",
                           
new XAttribute("Id", 1),
                           
new XElement("Name", "Huang Cong"),
                           
new XElement("Sex", ""))),
                           
new XComment("注释2")));
            doc.Save(
"test.xml");
        }
    }
}

转载地址:http://otje.baihongyu.com/

你可能感兴趣的文章
mySQL 多个表求多个count
查看>>
mysql 多字段删除重复数据,保留最小id数据
查看>>
MySQL 多表联合查询:UNION 和 JOIN 分析
查看>>
MySQL 大数据量快速插入方法和语句优化
查看>>
mysql 如何给SQL添加索引
查看>>
mysql 字段区分大小写
查看>>
mysql 字段合并问题(group_concat)
查看>>
mysql 字段类型类型
查看>>
MySQL 字符串截取函数,字段截取,字符串截取
查看>>
MySQL 存储引擎
查看>>
mysql 存储过程 注入_mysql 视图 事务 存储过程 SQL注入
查看>>
MySQL 存储过程参数:in、out、inout
查看>>
mysql 存储过程每隔一段时间执行一次
查看>>
mysql 存在update不存在insert
查看>>
Mysql 学习总结(86)—— Mysql 的 JSON 数据类型正确使用姿势
查看>>
Mysql 学习总结(87)—— Mysql 执行计划(Explain)再总结
查看>>
Mysql 学习总结(88)—— Mysql 官方为什么不推荐用雪花 id 和 uuid 做 MySQL 主键
查看>>
Mysql 学习总结(89)—— Mysql 库表容量统计
查看>>
mysql 实现主从复制/主从同步
查看>>
mysql 审核_审核MySQL数据库上的登录
查看>>