Removing a child of a node from an XmlNode

I use XPathnode to select the report. Now I want to know how I can remove this node from the document without knowing what node children they are with?

I tried calling .RemoveChildand it throws this error:

The node to be deleted is not a child of this node.

This is my code to remove node:

var node = doc.SelectSingleNode("//report");
doc.RemoveChild(node);
+4
source share
1 answer

You can find out the parent of node:

node.ParentNode.RemoveChild(node);

Please note that node.ParentNodemaybe null.

+5
source

All Articles