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

Working with the InsertBefore and InsertAfter Methods

If you need to insert a node in the middle of a container node's child list, you cannot use AppendChild or PrependChild. Instead, you must use InsertBefore and InsertAfter. Both methods take two XmlNode objects as parameters. The first XmlNode object is the XmlNode to be inserted. The second XmlNode object is the reference node. When using InsertBefore, the new node will be inserted before the reference node, and it will be inserted after the reference node when calling InsertAfter. Listing 11.22 creates two elements and adds one before the reference node and one after the reference node.

Listing 11.22.
 C# XmlDocument doc = new XmlDocument(); doc.LoadXml("<root><first/><last/></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