应用程序写Xml文档
2016-04-15 00:13
337 查看
主要用到CreateElement、CreateTextNode、CreateComment、AppendChild、InsertAfter方法
代码如下:
代码如下:
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();
相关文章推荐
- Rust-HayStack
- ELK实战-Logstash:收集rsyslog日志
- linux安装
- 每日一帖示例程序(使用TWebBrowser基于HTML做)
- eclips引入Java源代码
- java虚拟机涉及内存溢出
- 超 10 亿张患者医学图像被泄漏,但始终没引起医疗机构重视
- 一个JAVA class的秘密
- 百度搜索会议干货分享:移动时代流量的下一个风口在哪?
- JSP使用ajaxFileUpload.js实现跨域问题
- ASP.NET中BulletedList列表控件使用及详解
- ASP.NET Calendar日历(日期)控件使用方法
- ASP.NET中 CheckBox复选框控件的使用
- Python Web框架Tornado运行和部署
- 说一说Python logging
- php生成图片验证码的方法
- PHP使用pear实现mail发送功能 windows环境下配置pear
- php使用pear_smtp发送邮件
- PHP6连接SQLServer2005的三部曲
- php基于jquery的ajax技术传递json数据简单实例