2

I need to test a XHTML code like <div>&nbsp;</div> using XmlUnit. The Diff constructor tells me this:

org.xml.sax.SAXParseException: The entity "nbsp" was referenced, but not declared.

I know that nbsp entity is not defined in XML, but the HTML code is not mine, so I cannot replace it by #160 (that would be obvious solution otherwise).

I don't want to modify the HTML code by adding <!DOCTYPE html [ <!ENTITY nbsp "&#160;"> ]>, I would prefer to leave the code without change.

Is there another way around this problem? I know there is a HTMLDocumentBuilder class in XmlUnit, but I wasn't able to find good documentation or examples.

Richard
  • 279
  • 2
  • 9

2 Answers2

0

You can use a DOCTYPE declaration that refers to the MathML DTD:

<!DOCTYPE math 
    PUBLIC "-//W3C//DTD MathML 3.0//EN"
           "http://www.w3.org/Math/DTD/mathml3/mathml3.dtd">

or a local copy of the same.

1218985
  • 7,531
  • 2
  • 25
  • 31
  • 1
    If I wanted to add DTD, wouldn't it be better to add directly XHTML DTD? I believe this might be a solution, but I would prefer to leave source XHTML code without change (because your solution would raise some new issues). – Richard May 10 '13 at 17:01
0

You can enable Feature "http://apache.org/xml/features/continue-after-fatal-error" to not throw an exception in case of unknown entities. This still gives a warning though:

documentBuilderFactory.setFeature(
            "http://apache.org/xml/features/continue-after-fatal-error",
             true);

É voilá!