在网站后台中向XML文件中写入数据的方法。
XmlTextWriter writer = null;
string xmlname = Server.MapPath("mtstory.xml");//将XML文件保存在本地路径下
writer = new XmlTextWriter(xmlname, System.Text.Encoding.GetEncoding("gb2312"));
//开始一个新的XML文档
writer.WriteStartDocument();
writer.WriteStartElement("宝物故事");
writer.WriteStartElement("宝物备注", "");
writer.WriteString(story);
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Close();
XmlTextWriter writer = null;
string xmlname = Server.MapPath("mtstory.xml");//将XML文件保存在本地路径下
writer = new XmlTextWriter(xmlname, System.Text.Encoding.GetEncoding("gb2312"));
//开始一个新的XML文档
writer.WriteStartDocument();
writer.WriteStartElement("宝物故事");
writer.WriteStartElement("宝物备注", "");
writer.WriteString(story);
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Close();