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>ab</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.
Where it bites
A definition on its own is trivia. These are the pages where this term decides whether a document works.
- Parse errorsPCDATA invalid Char value (control character)The literal-character failure, in full.
- Parse errorsInvalid numeric character referenceThe escaped-character failure.
- Datatypesxs:base64Binary and xs:hexBinaryThe type to reach for when the value genuinely contains arbitrary bytes.
- ToolsXML escape & unescapeReports the characters in a string that XML will not accept.
Related terms
- Character referenceA &#nnn; or &#xhhhh; escape naming a Unicode code point directly, rather than by an entity name.
- PCDATAParsed character data: text content that the parser scans for markup, so < and & in it have meaning and must be escaped.
- UTF-8The default encoding for XML, and the one every conforming parser must support along with UTF-16.
- XML 1.1A revision of XML that widens the legal name characters and permits most control characters as escapes — almost never used, and best avoided.
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.