Reference to undeclared entity

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

The message, as .NET reports it
Reference to undeclared entity 'nbsp'. Line 1, position 11.

Why it happens

  • HTML entities in XML:  , ©. XML defines only five: <, >, &, ", '.
  • An entity declared in a DTD that is not processed (DtdProcessing.Ignore or Prohibit).

How to fix it

Replace the entity with the character itself or a numeric reference ( ). Converting HTML text before putting it into XML avoids it.

.NET throws an XmlSchemaValidationException at the first schema error unless XmlReaderSettings.ValidationEventHandler is set, which then receives every one with its line and position. A well-formedness error is an XmlException and ends reading whatever the settings.

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>