Removing an XML node

L

Leon Mayne

I have an XmlDocument object, xdReportGroups, and I would like to find and
remove a node with a particular ID from the document. The node could be
several levels down the tree.

I have tried the below code:

Dim xnNodeToRemove As XmlNode =
xdReportGroups.DocumentElement.SelectSingleNode(String.Format("//ReportGroup[@ID='{0}']",
ViewState("InitialReportGroupId")))
If xnNodeToRemove IsNot Nothing Then
xnNodeToRemove.ParentNode.RemoveChild(xnNodeToRemove)

This seems to run through fine but the document is not affected. Does making
changes to a referenced child node not affect the document itself? If not
then does anyone know the best way to do this?
 
L

Leon Mayne

Leon Mayne said:
I have an XmlDocument object, xdReportGroups, and I would like to find and
remove a node with a particular ID from the document. The node could be
several levels down the tree.

I have tried the below code:

Dim xnNodeToRemove As XmlNode =
xdReportGroups.DocumentElement.SelectSingleNode(String.Format("//ReportGroup[@ID='{0}']",
ViewState("InitialReportGroupId")))
If xnNodeToRemove IsNot Nothing Then
xnNodeToRemove.ParentNode.RemoveChild(xnNodeToRemove)

This seems to run through fine but the document is not affected. Does
making changes to a referenced child node not affect the document itself?
If not then does anyone know the best way to do this?

Nevermind, it was working. I accidentally added the above code /after/ I
bound the XML to my control.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top