using System.Xml.Linq; protected void WriteXml(string path) { XDocument Xdoc = new XDocument( new XDeclaration("1.0","utf-8","yes"), new XComment("Create Time:"+DateTime.Now), new XElement("mybook", new XElement("bookfir", new XAttribute("id",1), new XAttribute("name","book1"), new XElement("bookname","asp.net"), new XElement("bookprice",100) ), new XElement("booksec", new XAttribute("id",2), new XAttribute("name","book2"), new XElement("bookname","php"), new XElement("price",200) ) ) ); Xdoc.Save(path); }