using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.XML;
using System.XML.Xsl;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
XmlDocument doc = new XMLDocument();
doc.Load(Server.MapPath("test.XML"));
XslTransform trans = new XslTransform();
trans.Load(Server.MapPath("test.xsl"));
XML1.Document = doc;
XML1.Transform = trans;
}
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text.Trim() != "")
{
XmlDocument doc = new XMLDocument();
doc.Load(Server.MapPath("test.XML"));
XMLNodeList nodes;
XMLElement root = doc.DocumentElement;
nodes = root.SelectNodes(descendant::BOOK[TITLE=' + TextBox1.Text.Trim() + ']); foreach (XMLNode node in nodes) { root.RemoveChild(node); } TextBox1.Text = ; Response.Write(scriptalert('刪除成功')
nodes = root.SelectNodes("descendant::BOOK[TITLE='" + TextBox1.Text.Trim() + "']");
foreach (XMLNode node in nodes)
{
root.RemoveChild(node);
}
TextBox1.Text = "";
Response.Write("<script>alert('刪除成功')</script>");
doc.Save(Server.MapPath("test.XML"));
XslTransform trans = new XslTransform();
trans.Load(Server.MapPath("test.xsl"));
XML1.Document = doc;
XML1.Transform = trans;
}
else
{
Response.Write("<script>alert('請輸入要刪除的節點');</script>");
}
}
}
★ ★★★★test.xml XML文件完整程序代碼★★★★★
<?XML version="1.0" encoding="utf-8"?>
< PUBLICATION>
< BOOK>
< TITLE>C#數據庫系統開發完全手冊</TITLE>
< PAGES>628</PAGES>
< /BOOK>
< /PUBLICATION>