Hi I am trying to compare content of two xml files using xmlunit
Here are my input xmls
reference.xml
<?xml version="1.0" encoding="UTF-8"?>
<books>
<book>
<name>abc</name>
<isbn>9971-5-0210-0</isbn>
<author>abc</author>
<category></category>
</book>
<book>
<name>def</name>
<isbn>9971-5-0222-0</isbn>
<author>def</author>
</book>
</books>
compare.xml
<?xml version="1.0" encoding="UTF-8"?>
<books>
<book>
<name>abc</name>
<isbn>9971-5-0210-0</isbn>
<author>abc</author>
<category></category>
</book>
<book>
<name>def</name>
<isbn>9971-5-0222-0</isbn>
<author>def</author>
</book>
<book>
<name>ghi</name>
<isbn>9971-5-0222-0</isbn>
<author>test authora</author>
</book>
</books>
Here we can observe in the compare.xml
there are 3 book nodes.
and I am printing the total differences and count as below
DetailedDiff detDiff = new DetailedDiff(diff);
List differences = detDiff.getAllDifferences();
System.out.println("Total differences:-->"+differences.size());
for (Object object : differences) {
Difference difference = (Difference)object;
System.out.println("***********************");
System.out.println(difference);
System.out.println("***********************");
}
output:
**Total differences:-->4
Expected number of child nodes '5' but was '7' - comparing at /books[1] to at /books[1]
Expected text value ' ' but was ' ' - comparing at /books[1]/text()[3] to at /books[1]/text()[3]
Expected presence of child node 'null' but was 'book' - comparing at null to at /books[1]/book[3]
Expected presence of child node 'null' but was '#text' - comparing at null to at /books[1]/text()[4]
Instead is there any way so that i can consider change as only 1 (because I consider only one book node is added ignoring inner tags inside ) and also customize the output to our customized message