O'Reilly logo

Microsoft® .NET Compact Framework Kick Start by Ronnie Yates, Erik Rubin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Removing XmlNodes for an XmlDocument

In addition to inserting and replacing nodes, you may need to remove a node from the tree altogether. You can easily remove a node from the node tree by using the RemoveChild method on the XmlNode class.

The RemoveChild method takes one parameter: the node to remove. If this node is successfully removed, then it returns a reference to the removed node. If the node is not a child of the container node, then an ArgumentException is raised. Listing 11.26 shows how to use the RemoveChild method.

Listing 11.26.
 C# XmlDocument doc = new XmlDocument(); doc.LoadXml("<root><child/></root>"); doc.DocumentElement.RemoveChild(doc.DocumentElement.FirstChild); doc.Save("out.xml"); VB Dim doc As New XmlDocument() doc.LoadXml("<root><child/></root>") ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required