Home : Tutorials : XML Tutorial


logo.gif (8216 bytes)
 

CDATA Sections


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 &lt;song&gt; and end tag &lt;/song&gt;</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.


back to last pagenext page

 


Home : Tutorials : XML Tutorial

 

Copyright© 1998-2004 All Rights Reserved. No portion of this site may be reproduced or redistributed without prior written permission from VistaEdge Technologies

All registered trademarks appearing on this site are the property of their respective owners. Java is a trademark or registered trademark of Sun Microsystems, Inc. in the United States and other countries. This site is not connected to Sun Microsystems, Inc. and is not sponsored by Sun Microsystems, Inc.