Welcome 微信登录
编程资源 图片资源库 蚂蚁家优选 PDF转换器 软件资源

软件开发小程序制作系统集成与运维空间租用硬件开发视频监控技术咨询与支持——联系电话:0311-88999002/88999003

首页 / 软件开发 / C# / C#通过传入节点name及节点value来删除XML相应节点

C#通过传入节点name及节点value来删除XML相应节点2014-10-07
//通过传入节点name及节点value,来删除相应节点public static string OperateXml(string keyInfo, string valueInfo){if (File.Exists(filePath)){XmlDocument xmlDoc = new XmlDocument();xmlDoc.Load(filePath);XmlNode xnRoot = xmlDoc.SelectSingleNode("根节点");if (xnRoot == null){xnRoot = xmlDoc.CreateNode(XmlNodeType.Element, "根节点", "");xmlDoc.AppendChild(xnRoot);} XmlNodeList xnl = xmlDoc.SelectSingleNode("根节点").ChildNodes;for (int i = 0; i < xnl.Count; i++){XmlElement xe = (XmlElement)xnl.Item(i);if (xe.Name.Equals(keyInfo)){xnRoot.RemoveChild(xe);if (i < xnl.Count) i = i - 1;}}xmlDoc.Save(filePath);return null;}
本文URL地址:http://www.bianceng.cn/Programming/csharp/201410/45570.htm