Skip to main content

XML error · entity

Entity is not defined

An HTML entity was used in XML. Only five are predefined; everything else needs a DTD.

Entity 'nbsp' not defined (line 1)

What it means

XML predefines exactly five entities: & < > " and '. HTML defines hundreds more —  , ©, —, é — and none of them exist in XML unless the document declares them itself in a DTD.

This is another case permissive parsers miss: fast-xml-parser accepts an undefined entity reference without complaint, so   can survive one toolchain and break the next.

What usually causes it

  • HTML entities in XML content:  , ©, —, ….
  • Content copied from an HTML page or a WYSIWYG editor into a feed.
  • A CMS that escapes for HTML output and reuses the same escaping for XML.
  • A template shared between an HTML and an XML view.

How to fix it

  • Use a numeric character reference instead:   for  , © for ©.
  • Better still, write the character itself — the document is UTF-8, so © and — are fine literally.
  • Wrap HTML fragments in CDATA so their entities are not parsed as XML.
  • If you truly need named entities, declare them in an internal DTD subset.

The same error elsewhere

Different parsers, same defect. If you arrived with one of these messages, you are in the right place.

  • Xerces (Java)

    The entity "nbsp" was referenced, but not declared.
  • expat (Python)

    undefined entity  : line 1, column 12
  • .NET System.Xml

    Reference to undeclared entity 'nbsp'.
  • fast-xml-parser and similar

    (accepted — no error reported at all)

Before and after

Both snippets are re-checked by the test suite against the real parser: the first is confirmed to produce the exact error above, the second to parse cleanly.

Fails
<title>Acme&nbsp;Ltd</title>
Parses
<title>Acme&#160;Ltd</title>

Where this bites most

Get started

Bring order to the XML your team can't afford to ignore.

Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.