alex878
10-08-2012, 10:14 PM
Hi guys,
I’m trying to do something quite simple and join two xml files together.
Basically I have an XML file called Test.xml and another called Test1.xml. I would like copy the xml text from Text.xml (all child nodes within population) and paste it into Test1.xml right before the end tag </data>.
All I have managed to achieve so far is being able to copy all the xml text from Test.xml to Range(“A2”) (I cant seem to figure out if this xml text can be stored in a variable so I copied it to a cell).
From there I am tring to insert the contents in Range (“A2”) to Test1.xml right before the </data> tag but I am having no luck with using the insertbefor method.
Could someone please help or provide direction? Thanks.
Test.xml
<population>
<details>
<person>Joe</person>
<age>90</age>
</details>
</population>
Test1.xml
<data>
<hello>Joe</hello>
</data>
Sub Test()
Dim XMLDoc As New DOMDocument
Dim oXmlNode As IXMLDOMNode
Dim oXmlNodes As IXMLDOMNodeList
XMLDoc.Load ("c:\documents and settings\ncsald\desktop\Test.xml")
Set oXmlNodes = XMLDoc.SelectNodes("//details")
For Each oXmlNode In oXmlNodes
Worksheets("Sheet1").Range("A2") = oXmlNode.XML
Next
XMLDoc.Load ("c:\documents and settings\ncsald\desktop\Test1.xml")
Range("A2").InsertBefore "</data>"
XMLDoc.Save ("c:\documents and settings\ncsald\desktop\Test1.xml")
End Sub
I’m trying to do something quite simple and join two xml files together.
Basically I have an XML file called Test.xml and another called Test1.xml. I would like copy the xml text from Text.xml (all child nodes within population) and paste it into Test1.xml right before the end tag </data>.
All I have managed to achieve so far is being able to copy all the xml text from Test.xml to Range(“A2”) (I cant seem to figure out if this xml text can be stored in a variable so I copied it to a cell).
From there I am tring to insert the contents in Range (“A2”) to Test1.xml right before the </data> tag but I am having no luck with using the insertbefor method.
Could someone please help or provide direction? Thanks.
Test.xml
<population>
<details>
<person>Joe</person>
<age>90</age>
</details>
</population>
Test1.xml
<data>
<hello>Joe</hello>
</data>
Sub Test()
Dim XMLDoc As New DOMDocument
Dim oXmlNode As IXMLDOMNode
Dim oXmlNodes As IXMLDOMNodeList
XMLDoc.Load ("c:\documents and settings\ncsald\desktop\Test.xml")
Set oXmlNodes = XMLDoc.SelectNodes("//details")
For Each oXmlNode In oXmlNodes
Worksheets("Sheet1").Range("A2") = oXmlNode.XML
Next
XMLDoc.Load ("c:\documents and settings\ncsald\desktop\Test1.xml")
Range("A2").InsertBefore "</data>"
XMLDoc.Save ("c:\documents and settings\ncsald\desktop\Test1.xml")
End Sub