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"));
}
//添加節點
XMLNode XMLdoCSelect=XMLDoc.SelectSingleNode("user");
XMLElement el=XMLDoc.CreateElement("person"); //添加person節點
el.SetAttribute("name","風雲"); //添加person節點的屬性"name"
el.SetAttribute("sex","女"); //添加person節點的屬性 "sex"
el.SetAttribute("age","25"); //添加person節點的屬性 "age"
XMLElement xesub1=XMLDoc.CreateElement("pass"); //添加person節點的裡的節點
xesub1.InnerText="123";//設置文本節點
&nb