Is there an open source command-line tool (for Linux) to diff XML files which ignores the element order?
Example input file a.xml
:
<tag name="AAA">
<attr name="b" value="1"/>
<attr name="c" value="2"/>
<attr name="a" value="3"/>
</tag>
<tag name="BBB">
<attr name="x" value="111"/>
<attr name="z" value="222"/>
</tag>
<tag name="BBB">
<attr name="x" value="333"/>
<attr name="z" value="444"/>
</tag>
b.xml
:
<tag name="AAA">
<attr name="a" value="3"/>
<attr name="b" value="1"/>
<attr name="c" value="2"/>
</tag>
<tag name="BBB">
<attr name="z" value="444"/>
<attr name="x" value="333"/>
</tag>
<tag name="BBB">
<attr name="x" value="111"/>
<attr name="z" value="222"/>
</tag>
So comparing these 2 files should not output any differences. I have tried to sort the files with XSLT first:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="WINDOWS-1252" omit-xml-declaration="no" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*">
<xsl:sort select="@*" />
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
But the problem is that for the elements <tag name="BBB">
there is no sorting. They are simply output the order which they are input.
I have already looked at diffXml
, xDiff
, XMLUnit
, xmlstarlet
but none of these solve the problem; the diff output should be human readable, e.g. like when using diff
.
Any hints on how either the sorting or ignoring element-order diff can be solved? Thanks!