Using C#
How do you remove a specific node from an XMLDocument using XPATH?
forEach( x => x. parentNode. remove(x) );
To find nodes in an XML file you can use XPath expressions. Method XmlNode. SelectNodes returns a list of nodes selected by the XPath string. Method XmlNode.
Removing Nodes from the DOM Child nodes can be removed from a parent with removeChild() , and a node itself can be removed with remove() .
/* selects the root element, regardless of name. ./* or * selects all child elements of the context node, regardless of name.
If you want to delete nodes, that are not direct children of the documents root, you can do this:
XmlDocument doc = new XmlDocument();
// ... fill or load the XML Document
XmlNode childNode = doc.SelectSingleNode("/rootnode/childnode/etc"); // apply your xpath here
childNode.ParentNode.RemoveChild(childNode);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With