Is there any easy way in msxml to m开发者_Go百科erge two xml documents (IXMLDomDocuments)? I want to make one of the trees embedded as a child of the second one.
I saw that IXMLDomDocument3 offers importNode, but couldn't get it to work correctly. Is this the way to go or is there another solution?
Thanks, Dan
What programming language are you using?
Here's a working example in Javascript:
Given A.xml:
<base>
<A>
<one>
<two/>
</one>
</A>
</base>
B.xml:
<something>
<B/>
<BBBBBB/>
</something>
merge.js:
var doc1 = new ActiveXObject("MSXML2.DOMDocument");
doc1.load("A.xml");
var doc2 = new ActiveXObject("MSXML2.DOMDocument");
doc2.load("B.xml");
doc1.documentElement.appendChild(doc2.documentElement);
WScript.echo (doc1.xml);
The output is:
<base>
<A>
<one>
<two/>
</one>
</A>
<something>
<B/>
<BBBBBB/>
</something>
</base>
精彩评论