asp.net修改XML

来源:互联网 发布:能听的软件 编辑:程序博客网 时间:2024/05/20 19:49

 string path = HttpContext.Current.Request.PhysicalApplicationPath + "xml/bcastr.xml";
        string id = Request.QueryString["id"];
        XmlDocument myxdoc = new XmlDocument();
        myxdoc.Load(path);
        XmlNode imageNode = myxdoc.ChildNodes[1];
        XmlElement tempxe = null;
        foreach (XmlNode tempxn in imageNode.ChildNodes)
        {
            if (tempxn.Attributes["id"].Value == id)
            {
                tempxe = (XmlElement)tempxn;
                imageNode.RemoveChild(tempxe);
            }
        }
        tempxe.SetAttribute("link", TB_Link.Text );
        tempxe.SetAttribute("itemtitle", TB_Title.Text);
        imageNode.PrependChild(tempxe);
        myxdoc.Save(path);

原创粉丝点击