zoukankan      html  css  js  c++  java
  • 从配置文件中删除节点

      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;
                }
            }
  • 相关阅读:
    Thread.join()的使用
    Java 编程思想
    LoadRunner 常见错误
    Selenium+IDEA+Maven+TestNG环境搭建
    计算机基本知识了解(二)
    Java中int和Integer的区别
    计算机基本知识了解(一)
    Jmeter安装及环境配置
    app稳定性测试-monkey测试
    .net framework
  • 原文地址:https://www.cnblogs.com/chucklu/p/9036504.html
Copyright © 2011-2022 走看看