Category: C# General

How to remove multiple childnodes from an XML Node specified by XPath:

 public static XmlDocument RemoveNodes(string xPath,XmlDocument xmlRequest){

        XmlNodeList xmlNodeList = xmlRequest.SelectNodes(xPath);
        IEnumerator en = xmlNodeList.GetEnumerator();
        while (en.MoveNext())
        {
            XmlNode xmlNode = (XmlNode)en.Current;
            XmlNode xmlRoot = xmlNode.ParentNode;
            xmlRoot.RemoveChild(xmlNode);
        }
        return xmlRequest;
    }

 

Tags:

C#

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.