Inserts a new node, before a specified node, in the list of children of the current node. Text nodes are merged as appropriate.
xmlnode_object.InsertBefore(new_child, ref_child)
Prerequisites
None
Parameters
new_child
A required XmlNode object that is to be inserted into the list of children.
ref_child
An optional XmlNode object. If specified, it must be an existing child of the current node.
Remarks
The new_child node is inserted as a child of the current node, and a sibling of the ref_child node. It is inserted immediately before the ref_child node in the DOM tree.
If ref_child is omitted, the new_child is added to the beginning of the list of children.
The node to be added may be created by XmlDoc.CreateNode or may have been removed from the tree using RemoveChild.
You cannot insert a node that is a member of one document tree into a different document tree. Use the Clone method if you wish to insert a copy of a node from a different document.
If a text node is inserted next to another text node, the new text is merged with the old text node and the new node is freed.
Examples
Dim doc As XmlDoc
Dim root As XmlNode
Dim elem1 As XmlNode
Dim elem2 As XmlNode
Dim text As XmlNode
doc = New XmlDoc("my_doc")
root = doc.DocumentElement
elem1 = doc.CreateNode("element", "section1")
text = doc.CreateNode("text")
text.Value = "This is the data for section 1"
elem1.AppendChild(text)
root.AppendChild(elem1)
elem2 = doc.CreateNode("element", "section2")
root.InsertBefore(elem2, elem1)
See Also
XML Classes | xmldoc_object.CreateNode | xmlnode_object.AppendChild | xmlnode_object.InsertAfter