Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare XML ignoring order of child elements

Tags:

Does anybody know of a tool that will compare two XML documents. Belay that mocking… there’s more. I need something that will make sure each node in file 1 is also in file 2 regardless of order. I thought XML Spy would do it with the Ignore Order of Child Nodes option but it didn’t. The following would be considered the same:

<Node>     <Child name="Alpha"/>     <Child name="Beta"/>     <Child name="Charlie"/> </Node>  <Node>     <Child name="Beta"/>     <Child name="Charlie"/>     <Child name="Alpha"/> </Node> 
like image 467
Andrew Garrison Avatar asked Nov 19 '09 22:11

Andrew Garrison


People also ask

Does order matter in XML?

In the most general sense, XML element order does not matter, unless otherwise specified by the appropriate schema.

How do I compare two large XML files?

Just drag and drop the files you want to compare and select the option as compare with selected.


2 Answers

I wrote a simple python tool for this called xmldiffs:

Compare two XML files, ignoring element and attribute order.

Usage: xmldiffs [OPTION] FILE1 FILE2

Any extra options are passed to the diff command.

Get it at https://github.com/joh/xmldiffs

like image 147
joh Avatar answered Oct 03 '22 00:10

joh


With Beyond Compare you can use in the File Formats-Settings the XML Sort Conversion. With this option the XML children will be sorted before the diff.

A trial / portable version of Beyond Compare is available.

like image 20
larkee Avatar answered Oct 03 '22 01:10

larkee