从配置文件中删除节点
2023-09-11 14:14:21 时间
private List<string> _ignoreList; private void InitIgnoreList() { _ignoreList = new List<string> { "/configuration/appSettings/add[(@key='CMSTrialKey')]", "/configuration/appSettings/add[(@key='CMSApplicationGuid')]", "/configuration/appSettings/add[(@key='CMSApplicationName')]", "/configuration/connectionStrings", "/configuration/system.web/customErrors", "/configuration/appSettings/add[(@key='LISALastUpdatedVersionTime')]", "/configuration/appSettings/add[(@key='LISAUpdatedVersion')]" }; }
public void RemoveIgnore(XmlDocument doc) { foreach (var xpath in _ignoreList) { var nodeList = doc.SelectNodes(xpath); // apply your xpath here if (nodeList == null) { continue; } foreach (XmlNode node in nodeList) { Console.WriteLine(node.OuterXml); RemoveChildNode(node); } } } private void RemoveChildNode(XmlNode childNode) { var parentNode = childNode.ParentNode; if (parentNode == null) return; parentNode.RemoveChild(childNode); while (parentNode != null && !parentNode.HasChildNodes) { var ancestorNode = parentNode.ParentNode; ancestorNode?.RemoveChild(parentNode); parentNode = ancestorNode; } }
相关文章
- 静默安装oracle 11g,环境预检查时报错,SEVERE: [FATAL] PRVF-0002 : 无法检索本地节点名
- 扩展Web.config配置文件里的appSettings节点和connectionStrings节点配置项过多,提取出来独立配置
- el-tree节点模拟双击事件
- 基于MATLAB的信标节点位于等边三角形顶点的仿真
- 【Leetcode】剑指 Offer 18. 删除链表的节点(简单)
- kubernetes 集群 节点 加入 删除
- C#操作配置文件中appSettings,connectionStrings节点
- HDFS 名称节点的启动
- HDFS概念名称节点和数据节点-名称节点-文件系统元数据的持久状态
- 6、多节点集群环境下Kafka的Confluent Platform的下载安装配置手册
- nginx健康节点检查nginx_upstream_check_module 淘宝的upstream_check进行nginx后端检查 tengine
- 5G时间节点逼近 测试是不容忽视的一环
- 关于Cocos2d-x节点和精灵节点的坐标、位置以及大小的设置
- JavaScript HTML DOM replaceChild替换子节点
- C# 解析带前缀的Xml节点内容
- Java IO节点流和处理流