|
//首先查找是否已经存在要添加xEle = (XmlElement)xDoc.SelectSingleNode(string.Format("//Name[First=''''{0}'''' and Last=''''{1}'''']",FirstName.Text,LastName.Text)); if (xEle!=null) //已经存在 { Label3.Text = "already exist"; } else //不存在,可以添加 { XmlDocumentFragment xDocFrag = xDoc.CreateDocumentFragment(); XmlElement xContact = xDoc.CreateElement("Contact"); XmlElement xName = xDoc.CreateElement("Name"); XmlElement xFirst = xDoc.CreateElement("First"); xFirst.InnerText = FirstName.Text; XmlElement xLast = xDoc.CreateElement("Last"); xLast.InnerText = LastName.Text; xName.AppendChild(xFirst); xName.AppendChild(xLast); XmlElement xNote = xDoc.CreateElement("Note"); xNote.InnerText = FirstName.Text+"and"+LastName.Text; xContact.AppendChild(xName); xContact.AppendChild(xNote); xDocFrag.AppendChild(xContact); XmlNode xRoot = null; xRoot = xDoc.SelectSingleNode("//ContactDetails"); //ContactDetails if (xRoot!=null) { //xRoot.AppendChild(xDocFrag.FirstChild);// 加在最后 xRoot.PrependChild(xDocFrag.FirstChild); //加在最前,做为第一个子节点 //还有InsertBefore,InsertAfter(new,old) xDoc.Save(strXmlPath); Label3.Text = "add sucess"; // } else { Label3.Text = "add failed"; } 3.2 修改上一页 [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无组件生成缩略图方法详解
|