August 2003
Beginner to intermediate
600 pages
12h 57m
English
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.
C# XmlDocument doc = new XmlDocument(); doc.LoadXml("<root><first/><last/></root>"); ... |
Read now
Unlock full access