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.

Document syntax

PCDATA

Parsed character data: text content that the parser scans for markup, so < and & in it have meaning and must be escaped.

The term comes from DTD content models, where #PCDATA is how an element declares that it may contain text. Outside a DTD it survives as the name for the ordinary case: characters the parser reads, resolving entity references and recognising the start of any tag it meets.

The contrast is with a CDATA section, where the same characters are taken literally. Both end up as text nodes; the difference is only in what had to be escaped to get there.

Defined in
XML 1.0 §3.2.2
Category
Document syntax
Also written
#PCDATA, parsed character data

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.

  • Escaped markup in PCDATA arrives as characters, not as elements.

    document.xml
    <x>a &lt; b &amp; c</x>
    expression
    string(/x)

    What the engine returns

    a < b & c
  • An unescaped ampersand starts an entity reference, so what follows is read as a name — and the parser stops when no semicolon arrives.

    document.xml
    <x>Ada &amp Lovelace</x>

    What the engine returns

    EntityRef: expecting ';' (line 1)

What catches people out

  • The characters legal in a document are constrained: most C0 control characters cannot appear in PCDATA at all, escaped or not.
  • > does not strictly need escaping in content, but escaping it anyway avoids the one case where it does — the ]]> sequence.
  • A DTD content model of (#PCDATA) permits text only. Adding a child element there is a validity error, not a well-formedness one.

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.