Using the AppendChild and PrependChild Methods

The two most commonly used node-insertion methods are the AppendChild method, which appends the specified node as the last child of the current node, and PrependChild, which prepends the specified node as the first child of the current node. Listing 11.21 creates two elements, adds one to the beginning of the root node's list, and adds another to the end of the root node's list.

Listing 11.21.
 C# XmlDocument doc = new XmlDocument(); doc.LoadXml("<root/>"); XmlElement firstChild = doc.CreateElement("", "First", ""); XmlElement lastChild = doc.CreateElement("", "Last", ""); doc.DocumentElement.PrependChild(firstChild); doc.DocumentElement.AppendChild(lastChild); doc.Save("out.xml"); VB Dim doc As ...

Get Microsoft® .NET Compact Framework Kick Start now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.