The entity was referenced, but not declared

The document uses a named entity, like  , that XML does not define.

The message, as Java reports it
The entity "nbsp" was referenced, but not declared.

Why it happens

  • HTML entities in XML:  , ©, é. XML defines only <, >, &, " and '.
  • An entity declared in a DTD that is not read, for example because external DTD loading is turned off.

How to fix it

Replace the entity with the character itself or a numeric reference (  for a non-breaking space). When the XML is built from HTML text, convert the entities before writing it.

Java's schema validation (javax.xml.validation.Validator, and JAXB or Spring on top of it) throws at the first error unless you set an ErrorHandler whose error() records the SAXParseException and carries on; each one has getLineNumber() and getColumnNumber(). A well-formedness error ends parsing whatever the handler does.

The same problem in xmlvalid

xmlvalid validates with libxml2, which reports it as Entity not defined. It checks the whole document in your browser and lists every schema error with its line and column, not only the first.

Entity 'nbsp' not defined

Example

Reports the error
<p>Price:&nbsp;10</p>
Fixed
<p>Price:&#160;10</p>