Replaces a child of the current node with a new node.
xmlnode_object.ReplaceChild(new_child, old_child)
Prerequisites
None
Parameters
new_child
A required XmlNode object that specifies a new node in the current node’s DOM tree. This new node will be inserted as a child of the current node.
old_child
A required XmlNode object that specifies a child of the current node. This child will be removed from the DOM tree.
Remarks
The old_child node and its subtree are removed from the DOM tree and the new_child node and its subtree are put in its place. The old_child node and its subtree can then be placed at a different location in the same tree or they can be deleted.
The old_child node must be an immediate child of the current node.
You cannot place a node that is a member of one document tree into a different document tree. Use the Clone method if you wish to make a copy of a node for a different document tree.
If a node is removed from a DOM tree and is not placed somewhere else in the tree, it is deleted once the corresponding XmlNode object is destroyed.
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 = root.AddElementNode("section1", "Data for section 1")
elem2 = doc.CreateNode("element", "section2")
text = doc.CreateNode("text")
text.Value = "Data for section 2"
elem2.AppendChild(text)
root.ReplaceChild(elem2, elem1) ' Replace section1 with section2
See Also
XML Classes | xmlnode_object.RemoveAttribute| xmlnode_object.RemoveChild | xmlnode_object.RemoveElement