0

I am trying to compare below two XMLs... I am doing a similarity test.

XML1

<top> <first>true</first> <!--- control node 1 ----> <second> <!--- control node 2 ----> <secondpart1>ooo</secondpart1> </second> <third> <!--- control node 3 ----> <thirdpart1>zzzz</thirdpar1> </third> <third> <!--- control node 4 ----> <thirdpart1>zzzz</thirdpar1> <thirdpart2>zzzz</thirdpar2> </third> </top>

XML2

<top> <second> <!--- test node 1 ----> <secondpart1>ooo</secondpart1> </second> <third> <!--- test node 2 ----> <thirdpart1>zzzz</thirdpar1> </third> <third> <!--- test node 3 ----> <thirdpart1>zzzz</thirdpar1> <thirdpart2>zzzz</thirdpar2> </third> <first>true</first> <!--- test node 4 ----> </top>

I get this error

[different] Expected number of child nodes '1' but was '2'. Looks like it compares control node 3 with test node 3. And since the names of the elements match "third", it does the comparision. Is there a work around this kind of situation ?

This is my code

    Diff d = new Diff(xmlResponseTrim, serializedResponseTrim);
    DetailedDiff dd = new DetailedDiff(d);
    dd.overrideDifferenceListener(new IgnoreTextAndAttributeValuesDifferenceListener());
    System.out.println(dd);
    assertTrue(dd.similar());
NewQueries
  • 4,841
  • 11
  • 33
  • 39

1 Answers1

0

The ElementQualifier interface is what determines which elements XMLUnit compares to each other. For your specific case RecursiveElementNameAndTextQualifier would work, but it is not a general solution. In more complex cases you will have to implement the matching strategy in an implementation of your own.

Stefan Bodewig
  • 3,260
  • 15
  • 22