I have two XML files (XSD) which are generated by some tool.
The tool doesn't preserve the order of elements so although the content is equal comparing it as text will result as the files are different.
Is there some tool that can sort the elements before comparing and will enable text comparison of the documents?
Of course the sorting needs to be done recursively.
Data example:
File A:
<xml>
<A/>
<B/>
</xml>
File B:
<xml>
<B/>
<A/>
</xml>
I had a similar problem and I eventually found: http://superuser.com/questions/79920/how-can-i-diff-two-xml-files
That post suggests doing a canonical XML sort then doing a diff. The following should work for you if you are on Linux, Mac, or if you have Windows with something like Cygwin installed:
$ xmllint --c14n FileA.xml > 1.xml
$ xmllint --c14n FileB.xml > 2.xml
$ diff 1.xml 2.xml
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With