I need to compare 2 XML for which I use my custom difference listener that ignores Child Node Sequence sequences and attribute sequences:
if (difference.getId() == DifferenceConstants.CHILD_NODELIST_SEQUENCE_ID || difference.getId() == DifferenceConstants.ATTR_SEQUENCE_ID) return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
My code works well for:
<xml> <elem1 att1="abc" att2="def"></elem1> <elem1></elem1> </xml>
and
<xml> <elem1></elem1> <elem1 att2="def" att1="abc"></elem1> </xml>
However, I need these XMLs to be identical too:
<xml> <elem1> <elem2> <id>ABC</id> ..... </elem2> </elem1> <elem1> <elem2> <id>DEF</id> ..... </elem2> </elem1> </xml>
and
<xml> <elem1> <elem2> <id>DEF</id> ..... </elem2> </elem1> <elem1> <elem2> <id>ABC</id> ..... </elem2> </elem1> </xml>
Here I want the comparison to be considered as elem1 in both XMLs to be identical, since only the sequence has been mixed. Therefore, I need my code to work with more than one nesting level. Is this possible with XMLUnit? Help someone?
I found a workaround (I can not add a comment to my own requirements within 8 hours):
I used to redefine ElementQualifier with: ElementNameAndAttributeQualifier, if I change this to RecursiveElementNameAndTextQualifier, I can get the desired result
xmlDiff.overrideElementQualifier(new RecursiveElementNameAndTextQualifier());
You can also use multiLevelElementNameandTextQualifier to compare deepr level XML. Recursive only for level 1.
For more information, you can contact: http://xmlunit.sourceforge.net/userguide/html/ar01s03.html#ElementQualifier Example 20
I need to match Element Name and Attributes, and that matches Name and Text .. but still .. its working at the moment, so I use it.
Will be updated if I find a better solution.
Hope this helps someone :)