|
asp.net 操作xml(1) ASP.net 对XML文件的读写,添加,修改,删除操作 下面有代码调试正确
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Xml; private XmlDocument xmlDoc;
//load xml file private void LoadXml() { xmlDoc=new XmlDocument(); xmlDoc.Load(Server.MapPath("User.xml")); }
//添加节点 private void AddElement() { LoadXml();
XmlNode xmldoCSelect=xmlDoc.SelectSingleNode("user"); XmlElement el=xmlDoc.CreateElement("person"); //添加person节点 el.SetAttribute("name","风云"); //添加person节点的属性"name" el.SetAttribute("sex","女"); //添加person节点的属性 "sex"
|