I have the following testXML
<root>
<a>test</a>
<b>bee</b>
<d/>
</root>
While the templateXML looks like this
<root>
<a/>
<b/>
<c/>
<d>
<e/>
</d>
</root>
I want XMLUnit to return the missing elements, in this case 'c' and 'e' are missing
/root[1]/c[1] is missing
/root[1]/d[1]/e[1] is missing
My code looks like this
public static ArrayList<Difference> testCompareToSkeletonXML(String xml, String template) throws Exception {
XMLUnit.setCompareUnmatched(false);
XMLUnit.setIgnoreAttributeOrder(true);
XMLUnit.setIgnoreComments(true);
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true);
DifferenceListener myDifferenceListener = new IgnoreTextAndAttributeValuesDifferenceListener();
DetailedDiff myDiff = new DetailedDiff(new Diff(template, xml));
// myDiff.overrideDifferenceListener(myDifferenceListener);
myDiff.overrideElementQualifier(new RecursiveElementNameAndTextQualifier());
ArrayList<Difference> returnList = new ArrayList<Difference>();
List<Object> allDifferences = myDiff.getAllDifferences();
for(Object obj: allDifferences){
Difference dif = (Difference) obj;
if(dif.getTestNodeDetail().getNode()== null){
//returnList.add(dif);
System.out.println(dif.getControlNodeDetail().getXpathLocation());
}
}
return returnList;
}
The output generated looks like this
/root[1]/a[1]
/root[1]/b[1]
/root[1]/c[1]
/root[1]/d[1]
Thanks for the help
--SD