Working with CDATA


Just as an XML processor doesn't process unparsed entities, you can deliberately mark content within an XML document so that it isn't processed. This type of content is known as unparsed character data, or CDATA. CDATA in a document must be specially marked so that it is treated differently than the rest of an XML document. For this reason, the part of a document containing CDATA is known as a CDATA section. You define a section of CDATA code by enclosing it within the symbols <![CDATA[ and ]]>. Following is an example of a CDATA section, which should make the usage of these symbols a little clearer:

This is my self-portrait: <![CDATA[    *****   * @ @ *   *  )  *   * ~~~ *    ***** ]]>

In this example, the crude drawing of a face is kept intact because it isn't processed as XML data. If it wasn't enclosed in a CDATA section, the white space within it would be processed down to a few spaces, and the drawing would be ruined. CDATA sections are very useful any time you want to preserve the exact appearance of text. You can also place legitimate XML code in a CDATA section to temporarily disable it and keep it from being processed.




Sams Teach Yourself XML in 24 Hours
Sams Teach Yourself XML in 24 Hours, Complete Starter Kit (3rd Edition)
ISBN: 067232797X
EAN: 2147483647
Year: 2005
Pages: 266

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net