CDATA Sections
CDATA sections provide a way to tell the parser that there is no markup in the characters contained by the CDATA section. This makes it much easier to create documents containing sections where markup characters might appear, but where no markup is intended. CDATA sections are commonly used for scripting language content and sample XML and HTML content.
The CDATA section in the document map uses the following syntax.
<![CDATA[An in-depth look at creating applications with XML, using <, >,]]>
When an XML parser encounters the initial <![CDATA[
, it reports the content that follows as characters without attempting to interpret them as element or entity markup. Character references do not work within CDATA sections. When it encounters the concluding ]]>
, the parser stops reporting and returns to normal parsing.
For example, you can include either of the following CDATA sections in an XML document without causing the parser to report an error.
<![CDATA[</this is malformed!</malformed</malformed & worse>]]>
or
<![CDATA[if (c<10)]]>
Note
Content within CDATA sections must be within the range of characters permitted for XML content; control characters and compatibility characters cannot be escaped this way. In addition, the sequence ]]>
cannot appear within a CDATA section because this sequence signals the end of the section. This means that CDATA sections cannot be nested. The sequence also appears in some scripts. Within scripts, it is usually possible to substitute] ]>
for ]]>
.