anuvab1911 anuvab1911 - 5 months ago 27
Java Question

XMLUnit - How to compare a self-closing tag to one which isn't?

I have two pieces of XML, a part of which is :


<userActionRequiredCode xsi:nil="1" xmlns:xsi=""/>

These are in different files which I am comparing using XMLUnit.

These are different as you can see, not same, not similar. What options can I set for XMLUnit or the Diff class or anywhere so that I can take this difference into consideration.

Currently this doesn't show up in the list of differences.

Edit : Updated sample.


A simple MCVE shows them to be different, so if you don't get a difference, then you setup XMLUnit to not do so.

final String control = "<userActionRequiredCode>0</userActionRequiredCode>";
final String test = "<userActionRequiredCode xsi:nil=\"1\" xmlns:xsi=\"\"/>";

Diff myDiff =


Expected child nodelist length '1' but was '0' - comparing <userActionRequiredCode...> at /userActionRequiredCode[1] to <userActionRequiredCode...> at /userActionRequiredCode[1]