1

If I have two xml documents and store them into two javascript variables (xA and xB), how would I merge them together(with overwriting)?

For example

xA is

    <cat>
        <name type="asdf" >
            Bob
        </name>
        <color>
            brown
        </color>
        <length>
            8
        </length>
    </cat>

xB is

<root>
    <cat>
        <name type="fdsa" >
            Bob
        </name>
        <color>
            black
        </color>
        <weight>
            14
        </weight>
    </cat>
</root>

xB merge onto xA (stored as a variable xC) is

<root>
    <cat>
        <name type="fdsa" >
            Bob
        </name>
        <color>
            black
        </color>
        <length>
            8
        </length>
        <weight>
            14
        </weight>
    </cat>
</root>

And then I can print xC as string or save it, etc. How can I do this kind of merge in javascript?

Derek
  • 11,980
  • 26
  • 103
  • 162
  • MAybe this is of some help: http://stackoverflow.com/questions/80609/merge-xml-documents. It uses XSLT though, so that could be a little too much for this case – Koen Peters May 20 '12 at 14:00
  • You have to write code to do it. The browser will give you access to the DOM for each XML fragment, and then your code just has to do with it whatever it deems appropriate. There's no built-in "mergeXML" function. – Pointy May 20 '12 at 14:07

0 Answers0