Create XML using class XmlDocument
来源:互联网 发布:数据结构算法2.1 编辑:程序博客网 时间:2024/05/08 15:21
The result XML document is as follows:
- <?xml version="1.0" encoding="GB2312"?>
- <Books>
- <Book genre="Mystery" publicationdate="2001" ISBN="123456789">
- <title>The Case of the Missing Cookie</title>
- <author Country="America">
- <Name>Cookie Monster</Name>
- </author>
- <Price>$9.99</Price>
- </Book>
- </Books>
The C# code is:
- XmlDocument xmlDoc = new XmlDocument();
- // Create XML declaration
- XmlDeclaration xdl = xmlDoc.CreateXmlDeclaration("1.0", "GB2312", null);
- xmlDoc.AppendChild(xdl);
- // Create root node "Books"
- XmlElement books = xmlDoc.CreateElement("Books");
- // Create child node book infomation
- XmlElement book1 = xmlDoc.CreateElement("Book");
- // set node attributes
- book1.SetAttribute("genre", "Mystery");
- book1.SetAttribute("publicationdate", "2001");
- book1.SetAttribute("ISBN", "123456789");
- // create sub elements for book
- XmlElement title = xmlDoc.CreateElement("title");
- title.InnerText = "The Case of the Missing Cookie";
- book1.AppendChild(title);
- XmlElement author = xmlDoc.CreateElement("author");
- author.SetAttribute("Country", "America");
- book1.AppendChild(author);
- XmlElement authorName = xmlDoc.CreateElement("Name");
- authorName.InnerText = "Cookie Monster";
- author.AppendChild(authorName);
- XmlElement price = xmlDoc.CreateElement("Price");
- price.InnerText = "$9.99";
- book1.AppendChild(price);
- // add book information to books which is root element of the document
- books.AppendChild(book1);
- // add root node to document
- xmlDoc.AppendChild(books);
- // save the xml document to file system
- xmlDoc.Save("d://file1.xml");
- Create XML using class XmlDocument
- Create XML using class XmlTextWriter
- How to create Http Connection using AsyncTask class?
- XmlDocument 操作xml文档
- XmlDocument 操作xml文档
- XmlDocument 操作xml文档
- XMLDocument操作XML
- XMLDocument操作XML摘选
- XmlDocument操作xml文档
- C# XML XmlDocument
- 通过XmlDocument编辑Xml
- XmlDocument操作xml文档
- xml字符串转为XmlDocument
- 用XMLDocument解析xml
- C# XML XmlDocument
- Class.create
- 编写XML XmlTextWriter与XmlDocument
- 用XmlDocument创建XML文档
- Delphi技巧必读
- 一个程序员应该怎样去学习和掌握计算机英语呢
- CSS+DIV的网站重构在SEO中的优势
- Oracle分析函数参考手册
- 今天编辑了 "维基百科" 条目
- Create XML using class XmlDocument
- 取年份某周的開始日期和結束日期
- Google与Baidu的SEO优化差异性
- hiberante开发备忘录
- Join用法,HQL的方法,Hibernate中的fetch
- SQL查询语句精华使用简要
- 数据合并一例
- 水晶报表中动态保留数字字段小数位
- 经典JAVA程序迷题