I have two xmls, that needs to be compared. Number of elements in both the xml's may vary. Say for example consider below two xmls:
XML1:
<Students>
<Name Type="PG">
<GivenName>David</GivenName>
<Surname>John</Surname>
</Name>
<Name Type="PG">
<GivenName>Naveen</GivenName>
<Surname>S</Surname>
</Name>
<Telephone AreaCityCode="BLR">
<PhoneNumber No="+91-9643542222"/>
</Telephone>
<Telephone AreaCityCode="BLR">
<PhoneNumber No="+91-9643542258"/>
</Telephone>
<Email>David.JOHN@gmail.com</Email>
<Email>Naveen.S@gmail.com</Email>
<Address Type="PT">
<AddressLine>40 DICKENSON ROAD</AddressLine>
<AddressLine>BANGALORE 12</AddressLine>
</Address>
<Address Type="TP">
<AddressLine>DOUBLE ROAD</AddressLine>
<AddressLine>BANGALORE 20</AddressLine>
</Address>
</Students>
XML2:
<Students>
<Name Type="PG">
<GivenName>David</GivenName>
<Surname>John</Surname>
</Name>
<Name Type="PG">
<GivenName>Naveen</GivenName>
<Surname>S</Surname>
</Name>
<Telephone AreaCityCode="BLR">
<PhoneNumber No="+91-9643542222"/>
</Telephone>
<Telephone AreaCityCode="BLR">
<PhoneNumber No="+91-9643542258"/>
</Telephone>
<Email>David.JOHN@gmail.com</Email>
<Address Type="PT">
<AddressLine>40 DICKENSON ROAD</AddressLine>
<AddressLine>BANGALORE 12</AddressLine>
</Address>
<Address Type="TP">
<AddressLine>DOUBLE ROAD</AddressLine>
<AddressLine>BANGALORE 30</AddressLine>
</Address>
</Students>
In XML2, number of email
element is only one, but where as in XML1 it is two. My task is to compare the content of AddressLine
element irrespective of number of email
elements. I have written a piece of code for obtaining this as below:
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setIgnoreAttributeOrder(true);
XMLUnit.setIgnoreComments(true);
XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true);
DetailedDiff detailledDiff = new DetailedDiff (XMLUnit.compareXML(XML1, XML2));
detailledDiff.overrideElementQualifier(new ElementNameAndTextQualifier());
List<Difference> list = detailledDiff.getAllDifferences();
for (Difference difference : list) {
if(difference.getTestNodeDetail().getXpathLocation() == null)
System.out.println("control: "+difference.getControlNodeDetail().getXpathLocation());
if(difference.getControlNodeDetail().getXpathLocation() == null)
System.out.println("test: "+difference.getTestNodeDetail().getXpathLocation());
}
Even though there is a change in AddressLine
, it doesn't print the addressLine
XPath. Please help me out in resolving this issue. Thanks in advance