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

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

    0
  • And its characters arrive unescaped.

    document.xml
    <x><![CDATA[a < b & c]]></x>
    expression
    string(/x)

    What the engine returns

    a < b & c
  • Canonicalization erases the distinction entirely — the same content comes back escaped.

    document.xml
    <x><![CDATA[a < b]]></x>

    What the engine returns

    c14n
    <x>a &lt; 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.

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.