Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge XML documents [closed]

Tags:

I need to "merge" two XML documents, overwriting the overlapsed attributes and elements. For instance if I have document1:

<mapping>
    <key value="assigned">
        <a/>
    </key>
    <whatever attribute="x">
        <k/>
        <j/>
    </whatever>
</mapping>

and document2:

<mapping>
    <key value="identity">
        <a/>
        <b/>
    </key>
</mapping>

I want to merge the two like this:

<mapping>
    <key value="identity">
        <a/>
        <b/>
    </key>
    <whatever attribute="x">
        <k/>
        <j/>
    </whatever>
</mapping>

I prefer Java or XSLT-based solutions, ant will do fine, but if there's an easy way to do that in Rake, Ruby or Python please don't be shy :-)

EDIT: actually I find I'd rather use an automated tool/script, even writing it by myself, because manually merging some 30 XML files is a bit unwieldy... :-(

like image 678
Manrico Corazzi Avatar asked Sep 17 '08 06:09

Manrico Corazzi


People also ask

How do I combine multiple XML files into one XML?

You have to go to the Develop tab (show it if it's hidden). Then in the XML group, choose Import and select multiple XML files. That should work.

What is XML merge?

The XML Merge component is a transformation component used to take incoming data from upstream SSIS source components and merge them into one SSIS column data based on the XML data structure defined in the component. This data can be then consumed by a downstream pipeline component.


Video Answer


1 Answers

If you like XSLT, there's a nice merge script I've used before at: Oliver's XSLT page

like image 172
Craig.Nicol Avatar answered Nov 08 '22 20:11

Craig.Nicol