Introduction to XML in Flash
       by senocular

CDATA
There is one more type of XML node that should be mentioned. That element is a CDATA node. A CDATA (standing for Character DATA) node is a special node that looks somewhat like a cross between an element and a text node, though, it really exists as more of a resilient text node. It has a type of opening and closing tag but is meant to store body text inside the two. This text can be multi-lined and contain just about anything including those terror causing characters which would otherwise have to be replaced with character references in text nodes. The following XML has a CDATA section:

<text>
<![CDATA[ Here is a bunch of text.
And here is a little more: <, >, &, " and ' with no problem.
Expecting a third line? Neither was I!]]>
</text>

The opening tag of a CDATA section is <![CDATA[. Anything, and I mean anything, between that and the closing ]]> is part of that section. The only exception to this is another ]]>. You can't necessarily have a ]]> in a CDATA node because it would effectively close that node. Everything else, no matter what it is, between <![CDATA[ and ]]> is acceptable. The idea is that anything within a CDATA section is ignored by the XML parser, almost like a comment in the XML (XML comments are like HTML comments <!-- comment -->), but something from which you can still extract information from.

CDATA is often used for body text because of this (again, the only caveat here is that you cannot have ]]> in a CDATA section - this also prevents you from nesting CDATA sections - so you may need to watch for this if you are allowing others to dictate CDATA content). It's also especially useful in keeping markup like HTML or even other XML where replacing illegal characters (namely < and >) with their respective entity references causes an ugly mess.

The thing is that Flash doesn't directly provide much support for using them. There's no problem with using them, it's just that Flash will just treat them as normal text nodes. Any illegal characters passed into Flash via a CDATA section will be replaced with character references and the CDATA node itself will be replaced with a basic text node as a result. Don't worry, however, since should you need either versions (original or with character references) you will be able to get both.


 




SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple.