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

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 ...

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