Skip to main content

XML error · entity

CharRef: invalid decimal value

A numeric character reference was opened with &# and never closed with a semicolon, so the parser read past the digits into text that is not a number.

CharRef: invalid decimal value (line 2)

What it means

A numeric reference is & in decimal or & in hexadecimal, and the semicolon is part of the syntax rather than punctuation you can drop. Without it the parser keeps consuming characters as digits until it meets one that is not.

The message says "invalid decimal value" because that is what it was left holding — the digits plus whatever followed them. The defect is the missing terminator, not the number.

What usually causes it

  • Writing &#38 or &#160 without the closing semicolon.
  • An escaping pass that emitted the reference and a later pass that stripped semicolons.
  • Hand-written references copied from documentation that omitted the terminator.
  • A truncation that landed mid-reference.

How to fix it

  • Close every reference with a semicolon: & and &, never &#38.
  • Prefer writing the character directly — the document is UTF-8, so © and — need no reference at all.
  • Escape with a library rather than by hand; the semicolon is the part people forget.

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 reference to entity "#38" must end with the ';' delimiter.
  • expat (Python)

    not well-formed (invalid token): line 2, column 6
  • .NET System.Xml

    An error occurred while parsing EntityName.

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
<?xml version="1.0"?>
<root>&#38</root>
Parses
<?xml version="1.0"?>
<root>&#38;</root>

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.