Document syntax
CDATA section
A <![CDATA[ … ]]> block whose contents are treated as literal characters, so < and & inside it start nothing.
A CDATA section is an escaping convenience and nothing more. After parsing there is no CDATA node in any sense that matters downstream: the content is text, indistinguishable from the same characters written with entity references. A tool that round-trips a document may serialize it either way, and both are correct.
The one thing it cannot contain is the sequence that ends it. There is no escape for ]]> inside a CDATA section, so a block containing it has to be split in two — which is why wrapping arbitrary machine-generated text in CDATA is less safe than it looks.
- Defined in
- XML 1.0 §2.7
- Category
- Document syntax
- Also written
- <![CDATA[ ]]>, character data section
Shown, not asserted
All 3 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.
The markup inside a CDATA section is text: the element has no children.
document.xml <x><![CDATA[<y>not an element</y>]]></x>expression count(/x/*)What the engine returns
0And its characters arrive unescaped.
document.xml <x><![CDATA[a < b & c]]></x>expression string(/x)What the engine returns
a < b & cCanonicalization erases the distinction entirely — the same content comes back escaped.
document.xml <x><![CDATA[a < b]]></x>What the engine returns
c14n <x>a < b</x>
What catches people out
- ]]> cannot appear inside a CDATA section at all. Split it across two sections.
- CDATA does not survive canonicalization, and many serializers drop it. If a signature or a diff depends on it being there, it will break.
- It is not a comment. Everything inside is content and will be delivered to the consumer.
Where it bites
A definition on its own is trivia. These are the pages where this term decides whether a document works.
- Parse errorsSequence ']]>' not allowed in contentThe message when a bare ]]> appears in ordinary content.
- Parse errorsCData section not finishedWhat an unterminated CDATA section reports.
- NamespacesRSS content modulecontent:encoded is the best-known real use of CDATA — whole HTML documents inside a feed.
- ToolsXML canonicalizer (C14N)Shows what a CDATA section becomes once the distinction is normalised away.
Related terms
- PCDATAParsed character data: text content that the parser scans for markup, so < and & in it have meaning and must be escaped.
- Text nodeA run of character data in the tree, as a node in its own right — the model a query language sees rather than the markup you wrote.
- Predefined entityOne of the five entities every XML parser knows without a declaration: &, <, >, ' and ".
- Canonicalization (C14N)Rewriting a document into a single normal form — sorted attributes, expanded empty elements, resolved references, no declaration — so that equivalent documents become byte-identical.
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.