3

I am looking for a diff tool that allows me to compare 2 xml (or json) files ignoring the order of its elements.

Example:

<Node>
    <Child name="Alpha"/>
    <Child name="Beta"/>
    <Child name="Charlie"/>
</Node>

<Node>
    <Child name="Beta"/>
    <Child name="Charlie"/>
    <Child name="Alpha2"/>
</Node>

The 2 Node elements should be considered similar and the only difference to be shown is that Node1 has a child name "Alpha" which is "Alpha2" in the other node.

StackOverflow has a similar question, but it was asked 8 years ago, the solution no longer works. Is there a newer tool available?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
sidd607
  • 1,339
  • 2
  • 18
  • 29

4 Answers4

11

Depending on the size of XML use a diff tool with an adjustable skew tolerance - how far the algorithm would look for "similar" lines - and closeness matching.

"Naive" diff using Beyond Compare 4:

Naive diff

With closeness matching:

With closeness matching

This works very well when merging, say, Visual Studio *.sln files (XML) with thousands of lines :)

If that's not enough, there's an option for "XML Sort" conversion that applies a sorting XSLT to inputs.

Regular diff:

enter image description here

With "XML Sort" conversion:

Example

Where to apply it from:

XML format dialog

Oleg
  • 24,465
  • 8
  • 61
  • 91
0

Notepad++ has a compare plugin.

Richard
  • 874
  • 2
  • 9
  • 23
0

I have written an xml compare algorithm using xslt 1.0 which is here. You just need to modify the "file2" variable to compare the input xml file against.

https://github.com/sflynn1812/xslt-diff-turbo

It outputs results of mismatched branch and leaf nodes, and speed is based off of the amount of differences that should generally be expected. More differences then more slowness.

0

I see Altova has been suggested; there is also a comparison feature in oXygenXML that might suit your purposes. If you are looking for something more sophisticated that is aware of XML structure and can be integrated into your code, DeltaXML's XML Compare is the best choice.

OliverXML
  • 16
  • 2