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

Answer from joh on Stack Overflow
🌐
Xlcompare
xlcompare.com › compare-xml-files.html
Compare XML Files Online. Free. No Upload. Get the Semantic XML diffs.
October 3, 2009 - This function enables you to compare ... in a different sequence. By selecting the Ignore Order option, you ensure that the comparison focuses solely on the content, rather than the arrangement....
🌐
JSoftwareLabs
jsoftwarelabs.com › compare-diff-online › xml-comparison
Compare xml online - XML diff tool
Paste your XML code,compare the code side-by-side and see a detailed table with change locations. Our online diff checker tool boasts the capability to ignore the order & namespaces of XML elements or nodes, enhancing its versatility and accuracy.
🌐
Scooter Forums
forum.scootersoftware.com › home › beyond compare 4 discussion › general
Ignore XML attribute order when comparing XML - Scooter Forums
QT for example will save XML every time with attributes in a random order. Is there a way to configure BC4 to get it to show those lines as the same? Thank you for any help ... Hello, The Text Compare considers the positioning as important, but can align character by character within a line.
🌐
GitHub
github.com › joh › xmldiffs
GitHub - joh/xmldiffs: Compare two XML files, ignoring element and attribute order.
-x, --xml - instead of comparing two xml files, write sorted contents of FILE1 to FILE2. In this mode the --output option is ignored.
Starred by 96 users
Forked by 27 users
Languages   Python 100.0% | Python 100.0%
🌐
GitHub
github.com › xmlunit › xmlunit › issues › 139
Comparing XML files ignoring elements attribute Order · Issue #139 · xmlunit/xmlunit
July 9, 2018 - import org.custommonkey.xmlunit.Diff; import org.custommonkey.xmlunit.XMLAssert; import org.testng.annotations.Test; import org.xmlunit.builder.DiffBuilder; import org.xmlunit.builder.Input; import org.xmlunit.diff.DefaultNodeMatcher; import org.xmlunit.diff.ElementSelectors; import org.xmlunit.matchers.CompareMatcher; public class TestNg { @test public void testXmlUnit() { String ControlXML = "CCST810000510DRAGON76810000510500227681000051050024510DRAGON76810000510500117681000051050014510RKH5D10"; String testXml = "CCST810000510DRAGON76810000510500117681000051050014510DRAGON76810000510500227681000051050024510FHMTN10"; assertThat(testXml, CompareMatcher.isSimilarTo(ControlXML).ignoreWhitespace().normalizeWhitespace().withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText, ElementSelectors.byName)));
Author   vramsprsk
🌐
JSoftwareLabs
jsoftwarelabs.com › compare-diff-online › file-xml-comparison
Compare XML File online - XML diff tool
Upload your XML code files, compare the code side-by-side and see a detailed table with change locations. Our online diff checker tool boasts the capability to ignore the order & namespaces of XML elements or nodes, enhancing its versatility ...
Find elsewhere
🌐
ExtendsClass
extendsclass.com › xml-diff.html
XML diff - Compare xml online
The difference check is not able to sort tags before compare if the tag orders are mismatching in xml file1 with xml file2 ... convert: PHP to PythonPython to javascriptKotlin to javaTypeScript to JavaScriptXPath to CSS selectorjson to python object onlineJSON to PHPXML to JSON Converter
🌐
Altova
altova.com › xmlspy-xml-editor › compare-xml
Compare XML Files | Altova
The order of XML attributes is irrelevant because XML processors do not consider the sequence that attributes appear in a particular element. XMLSpy accounts for this and intelligently ignores the attribute order, but a conventional differencing utility cannot and would therefore report every ...
🌐
inSystems
insystems.nl › home › testing for equality of xml files having different ordering of nested elements
Testing for equality of xml files having different ordering of nested elements - inSystems
October 26, 2024 - Here, the central object is the ... code style). First we declare the two fragments that should be compared, then we register the namespace(s), and declare that we will ignore comments and whitespace....
Top answer
1 of 9
30

For xmlunit 2.0 (I was looking for this) it is now done, by using DefaultNodeMatcher

Diff diff = Diffbuilder.compare(Input.fromFile(control))
   .withTest(Input.fromFile(test))
   .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText))
   .build()

Hope this helps this helps other people googling...

2 of 9
19

My original answer is outdated. If I would have to build it again i would use xmlunit 2 and xmlunit-matchers. Please note that for xml unit a different order is always 'similar' not equals.

@Test
public void testXmlUnit() {
    String myControlXML = "<test><elem>a</elem><elem>b</elem></test>";
    String expected = "<test><elem>b</elem><elem>a</elem></test>";
    assertThat(myControlXML, isSimilarTo(expected)
            .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)));
    //In case you wan't to ignore whitespaces add ignoreWhitespace().normalizeWhitespace()
    assertThat(myControlXML, isSimilarTo(expected)
        .ignoreWhitespace()
        .normalizeWhitespace()
        .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)));
}  

If somebody still want't to use a pure java implementation here it is. This implementation extracts the content from xml and compares the list ignoring order.

public static Document loadXMLFromString(String xml) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    InputSource is = new InputSource(new StringReader(xml));
    return builder.parse(is);
}

@Test
public void test() throws Exception {
    Document doc = loadXMLFromString("<test>\n" +
            "  <elem>b</elem>\n" +
            "  <elem>a</elem>\n" +
            "</test>");
    XPathFactory xPathfactory = XPathFactory.newInstance();
    XPath xpath = xPathfactory.newXPath();
    XPathExpression expr = xpath.compile("//test//elem");
    NodeList all = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
    List<String> values = new ArrayList<>();
    if (all != null && all.getLength() > 0) {
        for (int i = 0; i < all.getLength(); i++) {
            values.add(all.item(i).getTextContent());
        }
    }
    Set<String> expected = new HashSet<>(Arrays.asList("a", "b"));
    assertThat("List equality without order",
            values, containsInAnyOrder(expected.toArray()));
}
🌐
dale lane
dalelane.co.uk › blog
Comparing XML files ignoring order of attributes and child elements « dale lane
October 6, 2014 - Instead, to compare two of my XML files, my approach is to sort them both so they have a consistent order, and then diff the sorted files using an existing visual diff tool. (On Windows, I prefer vsdiff from SlickEdit. On Mac, I prefer diffmerge.
🌐
Ali-ulvi
ali-ulvi.github.io › XML_equality_checker_comparer.html
XML Compare Test Tool
Sometimes we need to compare XML files ignoring their elements' order but there was not such FREE tool before. Now there is!
🌐
Online Text Compare
onlinetextcompare.com › xml
Compare XML files online
All XML comparisons and differences are done locally within your browser using JavaScript.
🌐
Oxygen XML
oxygenxml.com › home › board index › oxygen xml editor/author/developer › feature request
Diff Files and Dirs: Add Ignore Element order for XML documents - Oxygen XML Forum
Hello, I've just filed a new improvement request on our internal issue tracking system to add the possibility to ignore the order of the elements, similar to what already is done for attributes. You'll be notified when this feature will be available. Best Regards, Florin ... Hi Florin, out of curiosity (and because I could very well need this feature): Did your feature request make it to market? I use oxygen file diff v18 but do not seem to be able to diff xml files such that the change of order of neighbouring xml elements is not considered to be a difference.