修改节点

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Xml.XPath;
public partial class UpdateNode : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(Server.MapPath("~/students.xml"));
        //修改节点
        var node = xmlDoc.GetElementsByTagName("student")[2];
        node.ChildNodes[1].ChildNodes[0].Value = "G3-14";
        //替换节点
        //node.replaceData(1, 3, "jeff");
        //保存XML文件的修改
        xmlDoc.Save(Server.MapPath("~/students.xml"));
        Response.Write("<script>alert('修改节点完成')</script>");
    }
}

你可能感兴趣的:(修改)