• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 725
  • Last Modified:

XML help for MSXML2.DOMDocument

Hi everyone,

I need some help with MSXML2.DOMDocument object. I am using VBA and have the following scenario.

I have an XML structure as follows:

<SomeRootElement>
<Input>
</Input>
</SomeRootElement>

Then I have another XML structure as follows:
<Output>
<SomeElement>
</SomeElement>
</Output>

Now what I want to do is combine these XML structures, so I have:
<SomeRootElement>
<Input>
</Input>
<Output>
<SomeElement>
</SomeElement>
</Output>
</SomeRootElement>

basically, add the second XML structure as a child to the root element.

How can I do this using VBA?

Thanks!
Cheers!
xargon
0
xargon_123
Asked:
xargon_123
  • 2
1 Solution
 
fds_fatboyCommented:
Private Sub Example()
    Dim xmlDoc
    Dim xmlOutput
    Dim strXML1 As String
    Dim strXML2 As String

    strXML1 = "<SomeRootElement><Input></Input></SomeRootElement>"
   
    Set xmlDoc = CreateObject("MSXML2.DOMDocument")
    xmlDoc.loadXML strXML1      'If the xml is in a file use
                                '    xmlDoc.load fileSpec
                                'instead.
    strXML2 = "<Output><SomeElement></SomeElement></Output>"
    Set xmlOutput = CreateObject("MSXML2.DOMDocument")
    xmlOutput.loadXML strXML2   'If the xml is in a file use
                                '    xmlDoc.load fileSpec
                                'instead.
    xmlDoc.documentElement.appendChild xmlOutput.documentElement
   
    MsgBox xmlDoc.xml
   
    Set xmlDoc = Nothing
    Set xmlOutput = Nothing
End Sub
0
 
fds_fatboyCommented:
In an effort to improve the quality of my answers, please tell me what I would have had to have done to get an A grade?
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now