When I try to remove some of my child element with RemoveChild(). But throw exception. I attached my code below.
nodeName = doc.SelectSingleNode("//Equipment//DataCollections//EnabledIDs//MyID[@id='" + attrValue + "']");
// Found the nodeName successfully druing run time.
doc.DocumentElement.RemoveChild(nodeName);
// faild to Remove the node
Show error below:
An unhandled exception of type 'System.ArgumentException' occurred in System.Xml.dll
Additional information: The node to be removed is not a child of this node.
How can I remove the node?
[Update]
VS2005 & .NET 2.0 used.
I believe .RemoveChild is removing the child of the node you selected.
Are there any children under nodeName
or is it the leaf already?
Edit:
Actually you need to remove the Child of the Parent, try the following:
nodeName.parentNode.removeChild(nodeName)