CreateXMl

//设置xml文件存放的目录
string path = Server.MapPath("App_Data/new.xml");
//使用LINQ创建xml文件的内容
XDocument doc = new XDocument(
                 new XDeclaration("1.0", "utf-8", "yes"),
                      new XElement("People",
                                          new XElement("Person",
                                          new XAttribute("IDCard", "22030219771012***"),
                                          new XElement("Name", "张三"),
                                          new XElement("Sex", "男"),
                                          new XElement("Old", 20)
)
)
);
//保存为new.xml文件
doc.Save(path);
//在页面上输出xml文件内容
Response.Write(doc);
//设置网页显示的类型为XML文件
Response.ContentType = "text/xml";
Response.End();

原文地址:https://www.cnblogs.com/Yellowshorts/p/2867606.html