Forum Discussion

PrathapR's avatar
PrathapR
Frequent Contributor
5 years ago

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
 

2 Replies

    • PrathapR's avatar
      PrathapR
      Frequent Contributor

      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.