C#对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");
以上就是C#对XML读写的代码实例的详细内容,更多请关注其它相关文章!