I am trying to use XMLUnit 1.3 to compare two similar XML files. Basically every thing is same. file1 is a copy of file2.
But in File2 I have changed the order of some values/elements in one node.
file1.xml
<root>
<ent>
<value>
<string>ada,cmb</string>
</value>
</ent>
</root>
file2.xml
<root>
<ent>
<value>
<string>cmb,ada</string>
</value>
</ent>
</root>
In my case, thease two files must be equal. Is it possible to achieve this with XMLUnit ?
My code
public void testXml() throws ParserConfigurationException, SAXException, IOException {
String refXmlPaht = "../test1.xml";
String testXmlPaht = "../test2.xml";
Document doc1 = TransformXML.convertXmlToDom(refXmlPaht);
Document doc2 = TransformXML.convertXmlToDom(testXmlPaht);
Diff myDiff = new Diff(doc1, doc2);
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setIgnoreComments(true);
XMLUnit.setIgnoreAttributeOrder(true);
assertXMLEqual("pieces of XML are not similar ", myDiff, true);
assertTrue("but are they identical? " + myDiff, myDiff.identical());
}
XMLUnit response
junit.framework.AssertionFailedError: but are they identical?
org.custommonkey.xmlunit.Diff
[different] Expected text value 'ada,cmb' but was 'cmb,ada' - comparing <string ...>ada,cmb</string> at /root[1]/ent[1]/value[1]/string[1]/text()[1] to <string ...>cmb,ada</string> at /root[1]/ent[1]/value[1]/string[1]/text()[1]...
Thank you for help.
Best regards,
coban