Create XML using class XmlTextWriter
来源:互联网 发布:阿尔德里奇数据 编辑:程序博客网 时间:2024/05/17 02:14
This is an example to create XML document using XmlTextWriter in C#.
The following XML is the result i want to generate.
- <?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 as follows,
- XmlTextWriter xtw = new XmlTextWriter("d://file.xml", Encoding.Default);
- xtw.Formatting = Formatting.Indented;
- xtw.WriteStartDocument();
- xtw.WriteStartElement("Books");
- // First Book
- xtw.WriteStartElement("Book");
- // write book attributes
- xtw.WriteAttributeString("genre", "Mystery");
- xtw.WriteAttributeString("publicationdate", "2001");
- xtw.WriteAttributeString("ISBN", "123456789");
- // write book elements
- xtw.WriteElementString("title", "The Case of the Missing Cookie");
- // write sub element
- xtw.WriteStartElement("author");
- xtw.WriteAttributeString("Country", "America");
- xtw.WriteElementString("name", "Cookie Monster");
- xtw.WriteEndElement();
- xtw.WriteElementString("price", "$9.99");
- xtw.WriteEndElement();
- xtw.WriteEndElement();
- xtw.WriteEndDocument();
- // close writer
- xtw.Close();
- Create XML using class XmlTextWriter
- Create XML using class XmlDocument
- XmlTextWriter创建XML文件
- .NET操作XML--XMLTextWriter
- 用XmlTextWriter写XML文件
- 使用XmlTextWriter生成XML文件
- 编写XML XmlTextWriter与XmlDocument
- XmlTextWriter,XmlTextReader,XML 的读写
- 使用XmlTextWriter生成XML文件
- c# XmlWriter XmlTextWriter操作XML
- XmlTextWriter
- How to create Http Connection using AsyncTask class?
- 使用XmlTextWriter对象创建XML文件
- 使用XmlTextWriter对象创建XML文件
- 使用XmlTextWriter对象创建XML文件
- 利用xmltextreader和xmltextwriter读写xml文件
- 编写XML XmlTextWriter与XmlDocument(转)
- C# XmlTextWriter和XmlTextReader 读写XML文件
- 按钮随意托摆事件
- TEXTMETRIC 结构详解
- C#基础概念二十五问
- 查看日志
- 学习Spring.NET、NHibernate
- Create XML using class XmlTextWriter
- libjingle翻译之《Important Concepts(重要概念)之Threads(线程)》
- 交友十六字
- C#将XML+XSL文件转化为HTML文件的类
- jsf问题
- 用户控件传值的问题研究
- libjingle翻译之《Important Concepts(重要概念)之Naming Conventions(命名约定)》
- Java连接SQL Server 2000
- 一个完整的共享內存类