CDATA
March 29, 1999
As we have already said, it is a pretty good rule of thumb to
consider anything outside of tags to be character data, and
anything inside of tags to be considered markup. But alas, in
one case this is not true. In the special case of CDATA blocks,
all
tags and
entity references
are ignored by an XML processor
that treats them just like any old 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. What if you wanted to write
about an XML document in XML! Consider the following example
in which you would have an example tag in your XML Guide
written in XML:
<EXAMPLE>
<DOCUMENT>
<NAME>Coleen Merriman</NAME>
<EMAIL>cm@mydomain.com</EMAIL>
</DOCUMENT>
</EXAMPLE>
As you can see, you would be forced to use entity references
for all the tags. YUCK!
To avoid the inconvenience of translating all special characters,
you can use a CDATA block to specify that all character data
should be considered character data whether or not it "looks"
like a tag or entity reference.
Consider the following example:
<EXAMPLE>
<![CDATA[
<DOCUMENT>
<NAME>Coleen Merriman</NAME>
<EMAIL>cm@mydomain.com</EMAIL>
</DOCUMENT>
]]>
</EXAMPLE>
|
As you might have guessed, the character string ]]> is not
allowed within a CDATA block as it would signal the end of the
CDATA block.
|
Elements
Introduction to XML For Web Developers | Table of Contents
Comments
|