Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML Diff Tool for unordered comparison of 2 XMLs

Tags:

json

diff

xml

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?

like image 515
sidd607 Avatar asked Jan 03 '23 17:01

sidd607


1 Answers

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

like image 86
Oleg Avatar answered Jan 05 '23 14:01

Oleg