Home > Backend Development > XML/RSS Tutorial > C# code example for reading and writing XML

C# code example for reading and writing XML

Y2J
Release: 2017-04-28 10:45:39
Original
1361 people have browsed it

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");
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template