XML相关

来源:互联网 发布:sql replace函数用法 编辑:程序博客网 时间:2024/06/03 17:05

创建XML以及读取XML

using System;using System.Xml.Linq;namespace CsStudy{    class Program    {        static void Main()        {            XDocument xd = new XDocument(                new XDeclaration("1.0","utf-8","yes"),new XComment("注释来的"),                new XProcessingInstruction("xml-stylesheet",@"href=""stories.css"" type=""text/css"""),                new XElement("员工列表", new XAttribute("color", "red"), new XAttribute("size", "large"),                new XElement("员工", new XElement("姓名", "张三"), new XElement("姓名", "李四"))));            e.Save("e.xml");            XDocument e2 = XDocument.Load("e.xml");            Console.WriteLine(e2);            Console.ReadKey();        }    }}

输出:

<!--注释来的-->
<?xml-stylesheet href="stories.css" type="text/css"?>
<员工列表 color="red" size="large">
  <员工>
    <姓名>张三</姓名>
    <姓名>李四</姓名>
  </员工>
</员工列表>

0 0
原创粉丝点击