Now that you know the basics, this article explains how to use XML's more advanced constructs to author complex XML documents. Entities, namespaces, CDATA blocks, processing instructions - they're all in here, together with aliens, idiots, secret agents and buried treasure.
First up, CDATA. As explained in the previous article, the XML specification considers all text enclosed within tags to be character data. There is one important exception to this - CDATA blocks.
CDATA blocks are document sections explicitly marked as not containing markup, and are hence treated as character data by the parser. These blocks can contain pretty much anything - strings, numbers, symbols, ancient Egyptian hieroglyphics - and will be ignored by the parser.
A CDATA block typically begins with
<![CDATA[
and ends with
]]>
with the data enclosed within the two. Here's an example:
<?xml version="1.0"?>
<manual>
<function>split(str, pattern)</function>
<description>Split
a string <param>str</param> into component parts on the
basis of <param>pattern</param></description>
<example>
<![CDATA[
<?
split("apple,
vanilla, orange", ",");
?>
]]>
</example>
</manual>
CDATA blocks make it easy to add large blocks of text (including text containing
special characters, symbols or program code) to an XML document, yet have the parser treat it as regular character data. And so, while a parser might choke on this,
within a CDATA block, as this would merely serve to confuse the parser. If you
need to include this sequence within a CDATA block, it needs to be written as
]]>
This article copyright Melonfire 2001. All rights reserved.