码迷,mamicode.com
首页 > 其他好文 > 详细

应用程序写Xml文档

时间:2017-04-15 20:11:09      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:title   fresh   reader   dex   alt   insert   blog   auth   mit   

主要用到CreateElement、CreateTextNode、CreateComment、AppendChild、InsertAfter方法

代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
XmlDocument document = new XmlDocument();
            document.Load("XmlReader.xml");
            //Get the root element
            XmlElement element = document.DocumentElement;
            //Create new nodes
            XmlElement newbook = document.CreateElement("book");
            XmlElement newtitle = document.CreateElement("title");
            XmlElement newauthor = document.CreateElement("author");
            XmlElement newcode = document.CreateElement("code");
            XmlText title = document.CreateTextNode("C# From fresh to junior");
            XmlText author = document.CreateTextNode("simith");
            XmlText code = document.CreateTextNode("c# begin");
            XmlComment comment = document.CreateComment("append publish");
 
            //insert into xml document
            newbook.AppendChild(newtitle);
            newbook.AppendChild(newauthor);
            newbook.AppendChild(newcode);
            newtitle.AppendChild(title);
            newauthor.AppendChild(author);
            newcode.AppendChild(code);
            element.InsertAfter(newbook, element.FirstChild);
            document.Save("XmlReader.xml");
            Console.ReadKey();

应用程序写Xml文档

标签:title   fresh   reader   dex   alt   insert   blog   auth   mit   

原文地址:http://www.cnblogs.com/chenshizhutou/p/6715363.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!