XmlWrite

//创建XmlWriter实例
using (XmlWriter xw = XmlWriter.Create(Server.MapPath("user.xml")))
{
   xw.WriteComment("图书信息");//注释语句
   //根节点开始
   xw.WriteStartElement("Info");
   //定义子节点Record
   xw.WriteStartElement("Record");
   xw.WriteAttributeString("ID", "001");//附加属性
   xw.WriteElementString("Name", "小王");
   xw.WriteElementString("Tele", "1356578");
   xw.WriteEndElement();
   //定义子节点Record
   xw.WriteStartElement("Record");
   xw.WriteAttributeString("ID", "002");
   xw.WriteElementString("Name", "小刘");
   xw.WriteElementString("Tele", "1397568");
   xw.WriteEndElement();
   //根节点结束
   xw.WriteEndElement();
   Page.ClientScript.RegisterStartupScript(GetType(), "", "alert('写入XML文件成功!');", true);
}

你可能感兴趣的:(write)