[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Using CDATA sections for element content??

  • From: "Ernest G. Allen" <ernestgallen@e...>
  • To: Jerry Murray <Jmurray@I...>, xml-dev@l...
  • Date: Thu, 08 Feb 2001 08:28:01 -0800

using cdata

First of all, you _can_ have ']]' in a CDATA section as long
as the next character isn't '>'.  See production 21 in
"Extensible Markup Language (XML) 1.0 (Second Edition)":

    [21]    CDEnd   ::=  ']]>'
    
valid:         <![CDATA[ [2*[6+1]]=28 ]]>
not valid:     <![CDATA[ [2*[6+1]]>27 ]]>
valid:         <![CDATA[ [2*[6+1]] > 27 ]]>

As to your comment that you're not using external entities,
but may use internal entities, it doesn't really inside a
CDATA section.  It's the entity _references_ inside your
PCDATA that you should be concerned about.  

If you simply wrap the PCDATA inside a CDATA section you are
changing the PCDATA to CDATA, whether that's what you want
to do or not.  Any entity references inside the CDATA
section  will get "flattened" and come right through your
parser to your application.  For example, using the letter
"x" instead of a real "times" symbol, if you have

    <foo>14 &times; 2 = 28</foo>

it will come out as: 14 x 2 = 28 

while 
 
    <foo><![CDATA[14 &times; 2 = 28]]></foo>

will come out as: 14 &times; 2 = 28

To avoid this problem you would need to convert all of the
character entity references to some "real" characters.  If
you're using Unicode it shouldn't be too much of a problem,
but if you're using single-byte encodings you'll need to
keep track of the "font" as well since sometime the same
byte-code means different characters in different fonts.

And, as Bob Kline wrote, you can't nest CDATA sections. 
Because you cannot nest CDATA sections you can only wrap the
PCDATA portion of elements which contain child elements. 
Otherwise you'll turn the start and end tags of nested
elements into CDATA.

Overall, unless there's something really special or 
strange about how you're processing the XML stream, you 
probably shouldn't wrap all of your current PCDATA in 
CDATA sections. 


/s/ Ernest G. Allen

  



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.