tags:

views:

164

answers:

4

I have two XML files. They are similar, but there are two nodes of which either of the file have only one. I want to merge two sets of such documents in one single document where first the node of side A is taken, followed by the nodes of side B.

I'm not an experienced user of diff tools and downloaded KDiff3 to start somewhere.. Can anybody put me on the right path?

--EDIT--
Finding diff tools is something I can manage on my own.
But how to make one of these tools (doesn't matter which one) make the merging go automatically by first putting in the part from file1 and then from file2 is what I'm looking for. It's a rather extensive amount of files, so I'd preferably not have any intervention in the mergin process.

+1  A: 

DiffMerge. It is free and works for Windows, Mac OS X and Unix.

mouviciel
A: 

KDiff3 can put both input versions to the output file. There are buttons labelled A and B. You can click one of them to put one version to the merged result. Or you can click both of them and both versions will be included. Order of clicking these buttons will influence the order of inserted rows.

It can also merge whole directories.

The only problem seems to be with automation.

Keyboard shorcuts of KDiff3 can be configured in quite a rich manner, so I would try looking here and then maybe use some keyboard scripting application.

There may be some other more simple way :-)

Josef Sábl
is there a way I can make the program do this for me automatically? I don't want to be clicking buttons for all these files ...
borisCallens
+1  A: 

This sounds more like a software to create, then the software to find.

If you roll your own, you can add aditional checks that both XMLs are valid.

dmajkic
Hmm, I have been searching so long that I could have written a quick and dirty already now :SWeird, I'd have thought this was a rather straight forward thing to do.. but apparantly, It's not.
borisCallens
+1  A: 

This might be very problematic to do with a standard diff tool if the xml "nodes" are in any way similar. For example:

file1:

1 <node id="1" />
2 <node id="2a">
3   <content item="1"/>
4   <content item="2a"/>
5 </node>
6 <node id="3" />

file2:

1 <node id="1" />
2 <node id="2b">
3   <content item="1"/>
4   <content item="2b"/>
5 </node>
6 <node id="3" />

A standard diff tool is going to highlight lines 2 and 4 as needing to be merged, but even if you automatically add the lines from file2, you'll end up with an invalid xml file:

1 <node id="1" />
2 <node id="2a">
2 <node id="2b">
3   <content item="1"/>
4   <content item="2a"/>
4   <content item="2b"/>
5 </node>
6 <node id="3" />

You really need a diff/merge tool that is xml-aware. I found a description of one called XmlMerge, along with an example that shows it doing exactly what you're asking for. It's part of EL4J.

There is a dormant effort called XUpdate that has a fair amount of tools around it (both for generating the XUpdate diffs and for applying them). There are also some .net classes that use a different foundation. You will need to do some scripting to use either of these systems I think.

Zac Thompson
thanks for the research. By now I already put so much time in research I figured I could as well write a quick little C# app. Turned out I had it all written in <5 mins :PPost is usefull for future ref though. Thx
borisCallens