109

I have several config files in my .net applications which I would like to merge application settings elements etc.

I was about to begin doing it manually as I usually do, however thought there must be an XML diff GUI tool available somewhere.

The tool would be able to go to the element level to compare and display the differences etc.

However Google gave no substantive free tool results and no hints for anything of value.

Is such a tool available? That is very useful? For free?

Thanks in advance. :)

Edit:

Here is a bit of clarification of the functionality that would turn my error-prone, tedious manual job into a 1-minute simpler task (and potential to automate):

In KDiff3, you can do a diff/merge of entire directories. There is a hierarchical diff which is very accurate, user-friendly and clear. I was interested in finding a similar solution, however instead of directory hierarchy, an XML element hierarchy.

If there is no such open source software, I am considering creating one on CodePlex to provide this functionality.

Russell
  • 17,481
  • 23
  • 81
  • 125
  • 1
    I recently came across this website which does some xml and json comparison online. https://www.jsoftwarelabs.com/jslutils/xml-comparison – DJDeveloper Feb 25 '22 at 12:25
  • https://www.jsoftwarelabs.com/jslutils/xml-comparison – DJDeveloper Feb 25 '22 at 12:26
  • 1
    @DJDeveloper that one works just great. Had to compare two files with lists of different order and could easily verify if all elements where present even when in random order. – Hefaistos68 Mar 09 '22 at 14:15

11 Answers11

33

Have a look at File comparison tools, from which I am using WinMerge. It has an ability to compare XML documents (you may wish to enable DisplayXMLFiles prefilter for v2.14.0 or PrettifyXML for v2.16.x).

DisplayXMLFiles.dll - This plugin pretty-prints XML files nicely by inserting tabs and line breaks. This is useful for XML files that do not have line returns in convenient locations.

Note for v2.16.x

The plugin PrettifyXML is supplied with the software package. It can be activated as following:

  • Make sure that Plugins → Plugin Settings → Enable plugins is enabled.
  • Then use either File → Recompare As → Prettify XML or Plugins → Scripts → Prettify XML

For those who wish to play with deprecated DisplayXMLFiles, he needs to download e.g. winmerge-2.16.14-full-src.7z and copy Plugins\dlls\X64\DisplayXMLFiles.dll to WinMerge\MergePlugins\.

WinMerge in action

See also my feature comparison table.

dma_k
  • 10,431
  • 16
  • 76
  • 128
  • 6
    +1 Winmerge version 2.12.4.0; Menu "Plugin" -> "List" -> check "Enable Plugins"; Menu "Plugin" -> check "Automatic unpacking". Tested with XML file with file name with extension .xml and it seems to work. – Alessandro Jacopson Sep 14 '11 at 09:43
  • 11
    It doesn't deal well with attributes being in different orders, so it's usefulness might be limited, depending on your situation. – Michael Kohne Mar 08 '12 at 20:50
  • Use this transform on any XML files first to sort elements and attributes: http://stackoverflow.com/questions/4091085/xslt-to-sort-nodes-by-name – LarryDavid Apr 08 '14 at 11:34
  • 2
    Looks like the plugin is no longer available. – Fernando Gonzalez Sanchez May 23 '17 at 20:53
  • I'm not sure why it's not in the installer, but I was able to get it from their src repo on bitbucket / source code (sourceforge DL) : https://bitbucket.org/winmerge/winmerge/src/100f95d3ca3fd0d2b4f17a942997dfed63f8fab1/Plugins/dlls/?at=default – aCodeMonkey Apr 08 '19 at 21:18
  • 1
    There is an item in the menu: "File > Recompare As > XML" Version 2.16.8.0 – xforfun Aug 05 '21 at 07:18
22

I wrote and released a Windows application that specifically solves the problem of comparing and merging XML files.

Project: Merge can perform two and three way comparisons and merges of any XML file (where two of the files are considered to be independent revisions of a common base file). You can instruct it to identify elements within the input files by attribute values, or the content of child elements, among other things.

It is fully controllable via the command line and can also generate text reports containing the differences between the files.

Project: Merge merging three XML files

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
  • I've tried Project::Merge and unfortunately it was not able to cope with my task. I have HTML text in paras (`

    `) which is added formatting (like ``, ``). So Project::Merge shows that complete para was changed, it does not do in-depth word analysis.

    – dma_k Aug 23 '11 at 09:28
  • Yes, I'm sorry to say that XHTML (it will never do legacy HTML) support is pretty limited in that respect, as is text differencing within XML blocks in general. Most work so far have been focused on configuration-style XML files where free form character data is limited in its extent and usage. Hopefully I'll improve Project: Merge in this area in a future release. –  Aug 25 '11 at 17:05
  • 4
    -1, The OP asked about free software. Project Merge is trialware and also hasnt been updated in 3 years. – yourbuddypal Jul 02 '14 at 14:20
  • 3
    Project:Merge has now been replaced by Oso XML Merge: https://osocorporation.com/xmlmerge/index.php – leetNightshade Aug 04 '16 at 23:48
15

There are a few Java-based XML diff and merge tools listed here:

Open Source XML Diff written in Java

Added links:

dma_k
  • 10,431
  • 16
  • 76
  • 128
Chris Fulstow
  • 41,170
  • 10
  • 86
  • 110
11

KDiff3 is not XML specific, but it is free. It does a nice job of comparing and merging text files.

hlovdal
  • 26,565
  • 10
  • 94
  • 165
epotter
  • 7,631
  • 7
  • 63
  • 88
  • 4
    I agree I am using KDiff3 at the moment, however a tool specifically for XML that could go down to the element level would be terrific. – Russell Dec 09 '09 at 01:32
  • If a child of a node has changed, then surely the node itself has materially changed. I don't think I quite follow what a tool specific to XML would do in such a case that would be different from diff (pardon the pun). – Jarret Hardie Dec 09 '09 at 01:35
  • 2
    I was thinking from this perspective: the way KDiff does a hierarchical diff of directories, a hierarchical diff of elements could also work. So if an element has changed, then I agree, the parent elements should also be flagged as having changed. – Russell Dec 09 '09 at 01:38
  • Ah, I get it now, many thanks. You're looking for a diff tool that can report a change in a line of text that actually hasn't itself changed, but for which a "nested" line of text has changed. Gotcha. That *would* be very useful. Apologies for not cottoning-on earlier. – Jarret Hardie Dec 09 '09 at 01:48
  • 31
    everyone realizes that in xml the child nodes are not guaranteed to be in any specific order, so any "tool" that reported that something was not in the same order from one file to the next really won't be a real xml compliant tool –  Dec 09 '09 at 02:47
  • Yeah that makes this more complicated, however there may be ways to help the diff tool, eg. attributes may indicate which elements are the same in the two documents etc. Good point though :) – Russell Dec 09 '09 at 02:52
  • Even assuming we could control the order by ordering alphabetically first would eliminate any issues with XML element order. – Russell Feb 08 '11 at 00:24
  • 8
    If the order changes, then the elements are different. Depending on the semantics of the XML document in question, the order may, or may not, be significant. E.g. in XHTML obviously the order matters. – George Lund Oct 30 '13 at 14:56
  • 8
    The point is that a regular diff tool works line based. There are specific diff tools for e.g. CSV files that understand the format it is diffing. The better that understanding, the more effective the diffing can happen. A good XML diff tool would be able to parse the XML, use a schema to determine constraints such as whether order matters for example, and then use that knowledge to give a far more effective diff / merge experience. – Stijn de Witt Jul 11 '17 at 08:35
  • @JarrodRoberson I don't get your argument. A XML diff tool is used to visualize changes in the file, it's not used to validate it in any way. Order can obviously be very significant for many consumers of XML. – Alex Nov 15 '17 at 16:01
  • 1
    @Alex - order is not guaranteed by the XML specification and any specific parser implementation could change from version to version so the order in the text file is irrelevant to the order in the parsed result. –  Nov 15 '17 at 17:07
  • 1
    @JarrodRoberson You are being unnecessary general. A specific parser could very well guarantee order. And XML schemas are perfectly fine with defining order. Your argument that a xml-specialiced diff tool that shows differing order wouldn't be xml compliant is just strange. Again, it's a diff tool, not a validation tool. The purpose of a diff tool is to show changes between versions, of course it should show when you are moving things around. And the order might very well be the difference of the file being valid or not accordingly to a specific XML scheme. – Alex Nov 15 '17 at 22:05
  • elements and attributes in different orders **is different**, there is no arguing that saying that they can be in different orders and be the same is ignoring that fact. –  Nov 16 '17 at 15:42
4

Pretty Diff tool was created with XML in mind. Just ensure you click the option for "markup".

http://prettydiff.com/

austincheney
  • 807
  • 10
  • 9
  • But that is online tool, right? How can I apply changes from left to right or merge? – dma_k Aug 23 '11 at 10:22
  • 1
    You also need to change the options for sorting, otherwise it flags XML elements as changed when all they did was move (order doesn't matter in XML so this shouldn't appear as a change). It still doesn't sort nested sections based on their content though, so you will still see additions and removals of large XML blocks when all that happened was the elements changed order, so it's not possible to get a fine-grained diff. – Malvineous May 21 '19 at 03:15
3

While this is not a GUI tool, my quick tests indicated that diffxml has some promise. The author appears to have thought about the complexities of representing diffs for nested elements in a standardized way (his DUL - Delta Update Language specification).

Installing and running his tools, I can say that the raw text output is quite clear and concise. It doesn't offer the same degree of immediate apprehension as a GUI tool, but given that the output is standardized as DUL, perhaps you would be able to take that and build a tool to generate a visual representation. I'd certainly love to see one.

The author's "links" section does reference a few other XML differencing tools, but as you mentioned in your post, they're all proprietary.

Jarret Hardie
  • 95,172
  • 10
  • 132
  • 126
  • 5
    My experience is that: It can't handle reordering of elements at all, which is something that'd be expected in an XML tool (as an option, because sometimes order is important), and instead of minimal diffs it shows entire changed elements. Basically the diff file is just a whole new XML file if there are major formatting changes without big semantic changes. – SilverbackNet Jan 24 '13 at 02:07
2

I use TortoiseMerge, which is included in TortoiseSVN program

And we have talked about File Diff tools in this thread, not dedicated to XML though

https://stackoverflow.com/questions/1830962/file-differencing-software-on-windows

Community
  • 1
  • 1
YOU
  • 120,166
  • 34
  • 186
  • 219
  • 1
    Thanks S.Mark, as I mentioned to epotter, I already use KDiff3 for general file diffs, however I would really prefer an XML specific diff utility if it is available (if not, I will start up an open-source one :) ) – Russell Dec 09 '09 at 01:44
2

A7Soft provide XML comparison tools freeware and shareware:

http://www.a7soft.com

1

Altova's DiffDog has free 30-day trial and should do what you're looking for:

http://www.altova.com/diffdog/diff-merge-tool.html

0

This is a diff engine for java developers, but it comes with a demo interface - you might be able to use it: https://community.emc.com/docs/DOC-5042

AP.
  • 1
  • 1
0

I recommend you to use CodeCompare tool. It supports native highlighting of XML-data and it can be a good solution for your task.

JackD
  • 597
  • 4
  • 7