4

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
  • 704,970
  • 168
  • 1,303
  • 1,425
sidd607
  • 1,311
  • 2
  • 18
  • 29

3 Answers3

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
  • 23,483
  • 7
  • 58
  • 88
0

Notepad++ has a compare plugin.

Richard
  • 843
  • 2
  • 8
  • 21
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.