生成xml文档

来源:互联网 发布:besiege mac 下载 编辑:程序博客网 时间:2024/04/30 14:05

using System;
using System.Xml;

public class Sample
{

 public static void Main()
 {
 
  // Create the XmlDocument.
  XmlDocument doc = new XmlDocument();
  doc.LoadXml("<item><name>wrench</name></item>");

  // Add a price element.
  XmlElement newElem = doc.CreateElement("price");
  newElem.InnerText = "10.95";
  doc.DocumentElement.AppendChild(newElem);

  // Save the document to a file and auto-indent the output.
  XmlTextWriter writer = new XmlTextWriter("D://data.xml",null);
  writer.Formatting = Formatting.Indented;
  doc.Save(writer);
 }
}