CDATA Sections are used to escape blocks of text
containing characters which would otherwise be recognized as markup. All tags and
entity references are ignored by an XML processor that treats them just like any character
data. CDATA blocks have been provided as a convenience measure when you want to include
large blocks of special characters as character data, but you do not want to have to use
entity references all the time. For example writing a tutorial about XML would
contain:
| "In XML you need elements which have a
starting tag <song> and end tag </song>" |
The markup for this sentence would be:
<div> In XML you need elements which have a
starting tag <song> and end tag </song></div>
|
In order to avoid this misconvenience, XML has a method to treat markup as text (or
CDATA). This is done by simply enclosing the text with markup that we want to displayed
(not interpreted) in a CDATA element.
"<!CDATA[In XML you need elements which have
a starting tag <song> and end stag </song>]]>"
|
Between the start of the section, "<![CDATA[" and the end of the section,
"]]>", all character data is passed
directly to the application. The only string that cannot occur in a CDATA section is
"]]>". Comments are not recognized in a CDATA section. If present, the
literal text "<!--comment-->" will be passed directly to the application. The character string
]]> is not allowed within a CDATA block as it would signal the end of the CDATA block.
CDATA does not work in HTML. |