0

JDK 1.7.0 XMLUnit 1.3

When comparing this control XML string:

            String controlXml = "" +
                "<client>" +
                "   <name>Hello&nbsp;World</name>" +
                "</client>";

With this test XML string:

            String testXml = "" + 
                "<client>" +
                "   <name>Hello&nbsp;World</name>" +
                "</client>";

XMLUNIT returns false and I was expecting it to return true (no differences).

Here is my usage:

XMLUnit.setIgnoreComments(true);
XMLUnit.setIgnoreWhitespace(true);
Diff diff = new Diff(controlXml,testXml);
boolean result = diff.similar(); //result is false

I also get the following error in the console window:

[Fatal Error] :1:103: The entity "nbsp" was referenced, but not declared.

I'm not sure what to do here.

I looked into it and I got some info about EntityResolver using Google but it's all very confusing.

I need the entity to be treated as plain text. Logically, as plain text, they are equal.

I tried toggling with the following options:

        XMLUnit.setExpandEntityReferences(false);  //tried true, false
        XMLUnit.setIgnoreDiffBetweenTextAndCDATA(false);  //tried true, false

Nothing worked. Please help, I'm totally lost. Thanks!

TchiYuan
  • 4,258
  • 5
  • 28
  • 35
  • 2
    well, ` ` is not something that an XML processor will recognize unless it is explicitly declared. In XML there's only five [pre defined](http://www.w3.org/TR/2008/REC-xml-20081126/#sec-predefined-ent) entities; HTML, on the other hand, has about 250 of them. – forty-two Jan 20 '12 at 21:43

1 Answers1

0

It appears that there's a difference between character entities ( ) and numerical entities ( ).

XMLUnit has no problems with numerical entities as opposed to character entities.

I'm thinking that a simple character-entity-to-numerical-entity procedure should be sufficient to resolve my problem.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
TchiYuan
  • 4,258
  • 5
  • 28
  • 35