编程语言

img bgu

[ASP/ASP.net]最简单的XML创建、写入操作

发表于2004/10/22 11:03:00  850人阅读

分类: [My ASP/ASP.net(C#)]


   //建一個新的空的XML文檔
   XmlTextWriter objXml = new XmlTextWriter(Server.MapPath("Text.xml"),null);
   //格式化輸出XML文檔
   objXml.Formatting = Formatting.Indented;
   objXml.Indentation = 4;
   //寫入XML文檔標記
   objXml.WriteStartDocument();
   //寫入XML文檔注釋
   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");
   //關閉子元素、元素、根元素
   objXml.WriteEndElement();
   objXml.WriteEndElement();
   objXml.WriteEndElement();
   //清除緩存
   objXml.Flush();
   //關閉對像
   objXml.Close();
阅读全文
0 0

相关文章推荐

img
取 消
img