w3resource

XML CDATA

Syntax

<![CDATA[text content possibly containing literal <or &characters ]]>

CDATA sections can be used to “block escape” literal text when replacing prohibited characters with entity references is undesirable. CDATA sections can appear inside element content and allow < and & character literals to appear. A CDATA section begins with the character sequence <![CDATA[ and ends with the character sequence ]]>. Between the two character sequences, an XML processor ignores all markup characters such as <, >, and &. The only markup an XML pro-cessor recognizes inside a CDATA section is the closing character sequence ]>. The character sequence that ends a CDATA section ]]> must not appear inside the element content. Instead, the closing greater-than character must be escaped using the appropriate entity &gt;. CDATA sections cannot be nested.

Example of CDATA sections

<sometext>
<![CDATA[ They're saying "x < y" & that "z > y" so I guess that means that z > x ]]>
</sometext>

For all CDATA, the character literals which are prohibited, are not characters which are not literals and since they are not, it causes problems for exporting data in the form of other datasets like executing Processing Instructions.

Example of Built-in entity in element content

 <sayhello word='&apos;Hi&apos;' />

Use of the built-in entity &apos; inside attribute content.

Previous: XML prohibited character literals
Next: XML declarations



Follow us on Facebook and Twitter for latest update.