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;
                }
            }
  • 相关阅读:
    23 情态动词+完成时
    22 情态动词否定和疑问
    青山有幸埋忠骨,白铁无辜铸佞臣。
    Modern Perl
    en_windows_10_enterprise_ltsc_2019_x64_dvd_5795bb03
    Destinos & Nuevos Destinos
    TVB <十兄弟>
    Great Udemy Courses
    assembly language reference
    Alex Jones
  • 原文地址:https://www.cnblogs.com/chucklu/p/9036504.html
Copyright © 2011-2022 走看看