urs
urs

Reputation: 11

XmlUnit empty Elements

I try to compare two xml with xmlUnit. I have the following problem. When i have two empty elements like the example below xmlUnit identificate the elements as a difference. Can i configure xmlUnit to ignore this?

</name> and <name></name>

I am only interesting in difference like the next two examples.

<name>test1</name> and <name>test2</name>

difference: test1 and test2

or

<name>test1</name> and <name></name> difference test1 and ...

My code:

`

Diff diff = new Diff(fr1, fr2);
DetailedDiff detailedDiff = new DetailedDiff(diff);
List differenceList = detailedDiff.getAllDifferences();
List differences = detailedDiff.getAllDifferences();
for (Object object : differences) {
  Difference difference = (Difference)object;
  String node1;
  String node2;
  node1 = difference.getControlNodeDetail().getNode().getNodeName() + " " +              difference.getControlNodeDetail().getNode().getNodeValue();
   node2 = difference.getTestNodeDetail().getNode().getNodeName() + " " +    difference.getTestNodeDetail().getNode().getNodeValue();
}

`

Upvotes: 0

Views: 714

Answers (1)

Chai Ang
Chai Ang

Reputation: 481

Assuming your </name> is a typo and it is <name/> as per the comment,

then you could try the following.

        XMLUnit.setIgnoreWhitespace(true);

Seems to work for me.

ie. When I try to compare <Carp1></Carp1> with <Carp1/>.

Without the above setting, I get

Expected text value '
' but was '

' - comparing <CfgDN ...>
</CfgDN> at /CfgDN[1]/text()[19] to <CfgDN ...>

</CfgDN> at /CfgDN[1]/text()[19]

With the above setting, all is similar and identical.

Upvotes: 1

Related Questions