zl程序教程

您现在的位置是:首页 >  后端

当前栏目

C# 通过传入节点name及节点value,来删除XML相应节点

c#节点XML 删除 通过 value name 传入
2023-09-14 09:02:14 时间
//通过传入节点name及节点value,来删除相应节点 public static string OperateXml(string keyInfo, string valueInfo) if (File.Exists(filePath)) XmlDocument xmlDoc = new XmlDocument(); xmlDoc
//通过传入节点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;

}

动力节点王鹤|Spring Boot框架学习笔记(一)Xml 和 JavaConfig Spring Boot框架 • 官方下载地址 动力节点spring资料 • 视频观看地址 https://www.bilibili.com/video/BV1XQ4y1m7ex 第一章 Xml 和 JavaConfig Spring 使用 Xml 作为容器配置文件, 在 3.0 以后加入了 JavaConfig. 使用 java 类做配 置文件使用。