//建一新的空的xml文n
XmlTextWriter objXml = new XmlTextWriter(Server.MapPath(“Text.xml“),null);
//格式化出XML文n
objXml.Formatting = Formatting.Indented;
objXml.Indentation = 4;
//入XML文n擞
http://www.gaodaima.com/33915.html最简单的XML创建、写入操作_xml
objXml.WriteStartDocument();
//入XML文n注
objXml.WriteComment(“Created using an XML” + Context.Timestamp);
//入根元素
objXml.WriteStartElement(“BookList”);
//入元素
objXml.WriteStartElement(“Book”);
//入傩
objXml.WriteAttributeString(“Category”,”Technology”);
//入傩灾
objXml.WriteAttributeString(“PageCount”,”1234″);
//入子元素及文本值
objXml.WriteElementString(“Title”,”Professional Video Recorder Programming”);
//入子元素及文本值
objXml.WriteElementString(“ReleaseDate”,”02/02/2002″);
//入元素
objXml.WriteStartElement(“AuthorList”);
//入子元素及文本值
objXml.WriteElementString(“Author”,”Framcesca Unix”);
//入子元素及文本值
objXml.WriteElementString(“Author”,”william Soft”);
//P]子元素、元素、根元素
objXml.WriteEndElement();
objXml.WriteEndElement();
objXml.WriteEndElement();
//清除
objXml.Flush();
//P]ο
objXml.Close();
欢迎大家阅读《最简单的XML创建、写入操作_xml》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码