开发者

Merging two XMLDOMDocuments

开发者 https://www.devze.com 2022-12-20 16:40 出处:网络
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.

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消