August 2003
Beginner to intermediate
600 pages
12h 57m
English
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.
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>") ... |
Read now
Unlock full access