help with MSXML2.DOMDocument object in VBA

X

xargon

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
 
C

Cindy M -WordMVP-

Hi Xargon,

See below...
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?

Sub XMLStuff()
Dim XMLDoc1 As MSXML2.DOMDocument40
Dim XMLDoc2 As MSXML2.DOMDocument40
Dim XMLDoc3 As MSXML2.DOMDocument40
Dim newNode As MSXML2.IXMLDOMNode
Dim cloneNode As MSXML2.IXMLDOMNode

Set XMLDoc1 = CreateObject("MSXML2.Domdocument.4.0")
Set XMLDoc2 = CreateObject("MSXML2.domdocument.4.0")
Set XMLDoc3 = CreateObject("MSXML2.domdocument.4.0")
XMLDoc1.async = False
XMLDoc2.async = False
XMLDoc1.loadXML
"<SomeRootElement><Input>abc</Input></SomeRootElement>"
XMLDoc2.loadXML "<Output><SomeElement></SomeElement></Output>"
Set cloneNode = XMLDoc2.documentElement.cloneNode(True)
'Set newNode = XMLDoc1.SelectSingleNode("/")
XMLDoc1.documentElement.appendChild cloneNode
Debug.Print XMLDoc1.XML
End Sub

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top