Skip to main content

Search 400 pages — tools, formats, elements, namespaces, directory, comparisons, XPath, datatypes, glossary, parse errors, schema errors, use cases, guides, blog and product.

XML error · entity

CharRef: invalid hexadecimal value

A hexadecimal character reference begins with &#x but the characters before its semicolon are not hexadecimal digits.

CharRef: invalid hexadecimal value (line 1)

What it means

After &#x, XML accepts only hexadecimal digits 0–9, A–F and a–f until the required semicolon. Any other character means the parser cannot turn the reference into a Unicode code point.

The message is about syntax before it is about the resulting character. First make the digits valid; a separate invalid-character message may still follow if the resulting code point is forbidden in XML.

What usually causes it

  • A reference copied with the literal placeholder &#xZZ; or &#xNN; still in it.
  • A decimal value written after the x even though it contains digits outside hexadecimal notation.
  • A truncated or templated value that inserted punctuation before the closing semicolon.
  • Confusing a Unicode name such as U+00A9 with the digits a character reference expects.

How to fix it

  • Use only hexadecimal digits and close the reference with a semicolon: © for ©.
  • Remove the x when the number is decimal: © is the same character.
  • Prefer writing the Unicode character directly in a UTF-8 document when a reference adds no clarity.

The same error elsewhere

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

  • expat (Python)

    not well-formed (invalid token): line 1, column 9
  • Xerces (Java)

    A hexadecimal representation must immediately follow the &#x in a character reference.

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
<root>&#xZZ;</root>
Parses
<root>&#xA9;</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.