What CDATA Means
Syntax
<![CDATA[
raw text goes here
]]>
Why It’s Needed
Normally, XML parsers interpret <, >, and & as special markup characters.
If you want to include raw text that contains these characters, you wrap it in CDATA.
Example
Without CDATA (problematic):
<code>
if (a < b && b > c) { ... }
</code>
With CDATA (safe):
<code>
<![CDATA[
if (a < b && b > c) { ... }
]]>
</code>
Important Rules
-
CDATA can contain any text, but cannot include ]]> (since that ends the CDATA block).
-
CDATA does not prevent the XML parser from reading the text — it just prevents parsing of markup.
-
Equivalent to writing escaped characters (<, &) — CDATA is just more convenient.
In Short
-
CDATA Section = a way to include raw text in XML without escaping special characters.
-
Useful for embedding code, scripts, or text with symbols like <, >, and &.