I have two xml files which I need to compare using xmlunit
content of these xml files are always same except their order
ex:
<report>
<component name = "a">
<component name = "b"/>
<component name = "c"/>
</component>
</report>
Here the order of the inside component may be different like below
<report>
<component name = "a">
<component name = "c"/>
<component name = "b"/>
</component>
</report>
When I compare these two xml I want diff.similar() to be true.
What I tried so far is
try(FileInputStream fileStream1 = new FileInputStream(expXMLPath)) {
try(FileInputStream fileStream2 = new FileInputStream(genXMLPath)) {
InputSource inputSource1 = new InputSource(fileStream1);
InputSource inputSource2 = new InputSource(fileStream2);
diff = new Diff(inputSource1, inputSource2);
RegDiffListener ignorableElementsListener = new RegDiffListener(
ignorableXPathsRegex);
diff.overrideDifferenceListener(ignorableElementsListener);
diff.overrideElementQualifier(new ElementNameAndAttributeQualifier());
diff.overrideElementQualifier(new MultiLevelElementNameAndTextQualifier(1, true));
diff.overrideElementQualifier(new RecursiveElementNameAndTextQualifier());
// diff.overrideElementQualifier(new
// ElementNameAndTextQualifier());
return diff;
}
I tried with different option of overrideElementQualifier and nothing is working. Please let me know the solution.