Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vb xml - copy node

Status
Not open for further replies.

russland

Programmer
Jan 9, 2003
315
CH
i wanted to copy/append a child from one xml to another. "unfortunately", it also removes that child from the original xml. any idea on how to DUPLICATE it?

cheers
 
here's the solutions... cloneNode

Parameters
deep
Boolean. A flag that indicates whether to recursively clone all nodes that are descendants of this node. If True, creates a clone of the complete tree below this node. If False, clones this node and its attributes only.
Return Value
An object. Returns the newly created clone node.

Example
The following Microsoft® Visual Basic® example clones a node, and then appends it as a child of the top-level node.

Dim xmlDoc As New Msxml2.DOMDocument40
Dim root As IXMLDOMElement
Dim currNode As IXMLDOMNode
Dim MyNewNode As IXMLDOMNode
xmlDoc.async = False
xmlDoc.resolveExternals = False
xmlDoc.Load ("books.xml")
If (xmlDoc.parseError.errorCode <> 0) Then
Dim myErr
Set myErr = xmlDoc.parseError
MsgBox(&quot;You have error &quot; & myErr.reason)
Else
Set root = xmlDoc.documentElement
Set currNode = root.childNodes.Item(1)
Set MyNewNode = currNode.cloneNode(True)
root.appendChild MyNewNode
MsgBox xmlDoc.xml
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top