|
string str = Server.MapPath("Contack.xml");XmlDocument xDoc = new XmlDocument(); xDoc.Load(str); XmlElement xEle = null; //查看要修改的元素是否存在 xEle = (XmlElement)xDoc.SelectSingleNode(string.Format("//Name[First=''''{0}'''' and Last=''''{1}'''']",FirstName.Text,LastName.Text)); if (xEle==null) //不存在 { Label5.Text = "no exist"; } else //存在 { //下面是一种方法 /*xEle.ChildNodes[0].InnerXml = FirstName.Text + "Replace"; xEle.ChildNodes[1].InnerXml = LastName.Text + "Replace"; xEle.NextSibling.InnerXml = FirstName.Text + "and" + LastName.Text + "Replace";*/ //也可以这样 //true表示递归地克隆指定节点下的子树 XmlElement xNodeCopy = (XmlElement)xEle.CloneNode(true);// xNodeCopy.ChildNodes[0].InnerXml = FirstName.Text + "Replace"; xNodeCopy.ChildNodes[1].InnerXml = LastName.Text + "Replace"; //xNodeCopy.NextSibling.InnerXml = FirstName.Text + "and" + LastName.Text + "Replace"; //xNodeCopy.ParentNode.ReplaceChild(xNodeCopy,xEle); //这样是错误的,因为xNodeCopy只是clone了这个点及子点,并没有父点 xEle.ParentNode.ReplaceChild(xNodeCopy,xEle); } xDoc.Save(str); } 3.3 删除string str; str = Server.MapPath("Contack.xml"); XmlDocument xDoc = new XmlDocument(); xDoc.Load(str); XmlElement xEle = null; //查找是否有存在指定的点 xEle = (XmlElement)xDoc.SelectSingleNode(string.Format("//Name[First=''''{0}'''' and Last=''''{1}'''']",FirstName.Text,LastName.Text)); if (xEle!=null) //存在 { 上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] 下一页 [Web开发]一个关于ASP运行时间计算的代码 [Web开发]ASP:检测含有中文字符串的实际长度 [Web开发]asp 中英文字符长度检测判断函数 [Web开发]安全维护 IIS asp 站点的高级技巧 [C语言系列]NET 中C#的switch语句的语法 [Access]ASP&SQL让select查询结果随机排序的实现方法 [Web开发]ASP字符串截取函数 [Web开发][asp]关键词只替换一次的写法 [Web开发]XML与HTML在语法上的主要区别详解 [Web开发]Asp无组件生成缩略图方法详解
|