Skip to main content

XML error · syntax

PCDATA invalid Char value (control character)

A raw control character reached element content. XML 1.0 forbids most of them, and no escaping makes them legal — they must be removed at the source.

PCDATA invalid Char value 1 (line 2)

What it means

XML 1.0 permits only three characters below U+0020 — tab, newline and carriage return. Every other control character is banned from a document, and the ban is absolute:  is invalid too, so escaping does not rescue it.

The character is invisible, which is what makes this error frustrating. The document looks correct in an editor and fails in every parser, because the fault is a byte nobody can see.

The two snippets below make the point better than any description: they look identical, and they are not. The failing one carries a U+0001 between "bad" and "value" that your screen has no way to draw. If you are hunting one of these, stop reading the document and start reading its bytes — `xxd`, `hexdump -C`, or your editor's show-invisibles mode.

What usually causes it

  • A database column holding a control character that was written straight into an element.
  • Text pasted from a PDF, a terminal capture or a fixed-width mainframe export.
  • A vertical tab or form feed (U+000B, U+000C) surviving a document conversion.
  • A NUL byte from a fixed-length field that was never trimmed.
  • Binary data emitted into a text element instead of being base64-encoded.

How to fix it

  • Strip characters outside the legal set at the point of generation, not after the fact.
  • Base64-encode anything genuinely binary; XML text is not a container for arbitrary bytes.
  • Do not try to escape it —  is invalid for the same reason the raw byte is.
  • If control characters must survive a round trip, XML 1.1 permits them escaped, but support for XML 1.1 is thin enough that it is rarely the right answer.

The same error elsewhere

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

  • Xerces (Java)

    An invalid XML character (Unicode: 0x1) was found in the element content of the document.
  • expat (Python)

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

    '', hexadecimal value 0x01, is an invalid character.

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>badvalue</root>
Parses
<?xml version="1.0"?>
<root>badvalue</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.