Home >Backend Development >XML/RSS Tutorial >C# code example for reading and writing XML
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!