cancel
Showing results for 
Search instead for 
Did you mean: 

How to print all differences when comparing two xml files using XMLUnit2

SOLVED
Highlighted
Contributor

How to print all differences when comparing two xml files using XMLUnit2

Hi All,

Using XMLUnit2 to compare two xml files using groovy in soapui, it's comparing two files successfully.Would like to print all differences what it finds, but it just printing only first difference. XMLUnit1 supposes to print all differences, but would like to use XMLUnit2.

If any one have any idea, how to print please help me, It would be appreciated.

 

Code Using:

 

diff = DiffBuilder.compare(resxml1)
        .withTest( resxml2)
        .withNodeFilter(nodeFilter)
        .withAttributeFilter(attributeFilter)
        .ignoreComments()
        .ignoreWhitespace()
        .ignoreElementContentWhitespace()
  .checkForSimilar()
        .withNodeMatcher(new DefaultNodeMatcher(new ByNameAndTextRecSelector(), ElementSelectors.byName))
         .build();
print diff
 
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: How to print all differences when comparing two xml files using XMLUnit2

That is the default feature for XmlUnit.

Here you go to achieve what you are after
https://www.baeldung.com/xmlunit2


Regards,
Rao.

View solution in original post

2 REPLIES 2
Highlighted
Community Hero

Re: How to print all differences when comparing two xml files using XMLUnit2

That is the default feature for XmlUnit.

Here you go to achieve what you are after
https://www.baeldung.com/xmlunit2


Regards,
Rao.

View solution in original post

Contributor

Re: How to print all differences when comparing two xml files using XMLUnit2

Thanks @nmrao ,

 

Also heared below answer from XMLUnit community,

 

The Diff object you get as a result of the comparison contains all differences and you can access them with diff.getDifferences(). The toString method of Diff that you invoke when you print it only prints the first difference.

So if you want to print all differences you'd do something like

for (Difference d : diff.getDifferences()) {
    System.err.println(d);
}

For more control over the output take a look at ComparisonFomatter and Difference's one-arg toString method.