Skip to main content
XMLDir

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

Encoding and characters

Invalid XML character

A code point XML forbids in a document at all — most of the C0 control range — which cannot be included literally or as an escape.

XML 1.0 permits tab, line feed and carriage return from the control range, and nothing else below U+0020. There is no escape hatch: `` is as illegal as a literal byte 0x01, because the restriction is on the character rather than on how it was written.

This is the failure mode of exporting text that came from somewhere else — a database column holding a stray 0x0B, a log line with an ANSI escape, a form field pasted from a terminal. The document looks fine and no parser will read it.

Defined in
XML 1.0 §2.2
Category
Encoding and characters
Also written
illegal character, control character

Shown, not asserted

All 2 claims are executed on every test run, against the same engines the tools use. If the behaviour changes, the test fails rather than this page quietly becoming wrong.

  • A literal control character in content is fatal.

    document.xml
    <x>ab</x>

    What the engine returns

    PCDATA invalid Char value 1 (line 1)
  • And escaping it does not help — the character itself is forbidden.

    document.xml
    <x>a&#1;b</x>

    What the engine returns

    xmlParseCharRef: invalid xmlChar value 1 (line 1)

What catches people out

  • Escaping is not a workaround. Strip these characters, or encode the whole value in base64, before it reaches the document.
  • XML 1.1 permits them as escapes, which is the one genuine reason anybody reaches for it — and it is usually still the wrong answer.
  • The two failures produce different messages depending on whether the character was literal or escaped, so search for both.

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.