CDATA Sections
CDATA sections are used to escape text that contains characters that would otherwise be recognized as markup.
Productions
[18] CDSect ::= CDStart CData CDEnd [19] CDStart ::= '<![CDATA[' [20] Cdata ::= (Char* - (Char* ']]>' Char*)) [21] CDEnd ::= ']]>'
Examples
<markup><![CDATA[
< and & are characters used in markup]]>
</markup> <company><![CDATA[
Simon & Associates]]>
</company>
Description
A CDATA section begins with the characters <![CDATA[
and ends with ]]>
. CDATA sections in XML allow you to
hide characters like <
and
&
from an XML processor.
These characters have special meaning in markup; <
begins an element tag and &
begins a character reference or
entity reference.
When processed, the &
character in the CDATA section is hidden from the processor so that
it isn’t interpreted as markup, as the start of an entity or
character reference would be. As with comments, CDATA sections
cannot be nested. A CDATA section must not contain ]]>
.
See also
§2.7
Get XML Pocket Reference, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.