Home  >  Article  >  Backend Development  >  C# code example for reading and writing XML

C# code example for reading and writing XML

Y2J
Y2JOriginal
2017-04-28 10:45:391326browse

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath("Content.xml"));//content.xml是自己所写的xml文件
XmlElement newElement = xmlDoc.CreateElement("留言板");
XmlElement elid = xmlDoc.CreateElement("id");
XmlElement elname = xmlDoc.CreateElement("name");
XmlElement elcomment = xmlDoc.CreateElement("comment");
XmlElement elback = xmlDoc.CreateElement("back");
elid.InnerText = ReturnCount();
elname.InnerText = this.name0.Text.Trim();
elcomment.InnerText = this.comment0.Text.Trim();
elback.InnerText = " ";
newElement.AppendChild(elid);
newElement.AppendChild(elname);
newElement.AppendChild(elcomment);
newElement.AppendChild(elback);
xmlDoc.DocumentElement.AppendChild(newElement);
xmlDoc.Save(Server.MapPath("Content.xml"));
Response.Redirect("View.aspx");

The above is the detailed content of C# code example for reading and writing XML. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn