CDATA in XML

CDATA stands for Character Data. CDATA opening/closing tag between data that could be interpreted as XML markup, but not actually.

You can use for escaping some characters, otherwise this will be treated as regular XML.

How to write CDATA in XML

Syntactically, CDATA behavior similar to a comment still 3 minor different between CDATA and Comment,

  • CDATA is a part of document while comment is not a part of document.

  • Both syntax are different.

  • Entities are recognize in CDATA while comment is not recognize.

CDATA Syntax

XML CDATA section you can write by following syntax,

<!CDATA[
  ------ CDATA Section Code ------
  ------ CDATA Section Code ------
]]>

CDATA Example

<?xml version="1.0" encoding="UTF-8"?>
<employee>
  <emp_info id="1">
    <name>
      <first_name>Opal</first_name>
      <middle_name>Venue</middle_name>
      <last_name>Kole</last_name>
    </name>
    <contact_info>
      <entities><![CDATA[
    This is the CDATA area.
    You can storing special character that are recognize. Ex. '  " & < >
    ]]></entities>
    </contact_info>
  </emp_info>
</employee>

Run it...   »

Example Result:

xml_cdata_example.xml


xml_cdata_example.xhtml