Private Sub Form_Load() Dim domFree As FreeThreadedDOMDocument50 Dim domApt As DOMDocument50 Dim node As IXMLDOMNode Dim clone As IXMLDOMNode Dim msg As String msg = "" Set domFree = New FreeThreadedDOMDocument50 Set domApt = New DOMDocument50 domApt.async = False If False = domApt.Load(App.Path + "\doc1.xml") Then MsgBox "can't load doc1.xml" Exit Sub End If domFree.async = False If False = domFree.Load(App.Path + "\doc2.xml") Then MsgBox "can't load doc2.xml" Exit Sub End If ' Copy a node from domFree to domApt: ' Fetch the "/doc" (node) from domFree (doc2.xml). ' Clone node for import to domApt. ' Append clone to domApt (doc1.xml). ' Set node = domFree.selectSingleNode("/doc") Set clone = domApt.importNode(node, True) domApt.documentElement.appendChild clone domApt.documentElement.appendChild domApt.createTextNode(vbNewLine) msg = msg + "doc1.xml after importing /doc from doc2.xml:" msg = msg + vbNewLine + domApt.xml + vbNewLine Set node = Nothing Set clone = Nothing ' Clone a node using importNode() and append it to self: ' Fetch the "doc/b" (node) from domApt (doc1.xml). ' Clone node using importNode() on domApt. ' Append clone to domApt (doc1.xml). ' Set node = domApt.selectSingleNode("/doc/b") Set clone = domApt.importNode(node, True) domApt.documentElement.appendChild domApt.createTextNode(vbTab) domApt.documentElement.appendChild clone msg = msg + "doc1.xml after import /doc/b from self:" msg = msg + vbNewLine + domApt.xml + vbNewLine Set node = Nothing Set clone = Nothing ' Clone a node and append it to the dom using cloneNode(): ' Fetch "doc/a" (node) from domApt (doc1.xml). ' Clone node using cloneNode on domApt. ' Append clone to domApt (doc1.xml). ' Set node = domApt.selectSingleNode("/doc/a") Set clone = node.cloneNode(True) domApt.documentElement.appendChild clone msg = msg + "doc1.xml after cloning /doc/a from self:" msg = msg + vbNewLine + domApt.xml + vbNewLine Set node = Nothing Set clone = Nothing domApt.save App.Path + "\out.xml" msg = msg + "a new document was saved to out.xml in the current working directory." MsgBox msg End Sub
Try It!