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

Re: CDATA vs. Escaped characters


xml escaped characters
> Using <doc>foo<![CDATA[bar]]>baz</doc>, the DOM gives you 3 children of
> element 'doc' ...or in SAX, 3 separate calls to characters():
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Sorry to nit-pick, but this doesn't necessarily have to be so.

SAX1 allows the parser to resutn character data in any cobination of events it likes.  i.e.

<foo>123456</foo>

could appear as 1 characters("123456", 0, 6) event, one characters("123", 0, 3) and one characters("456", 4, 3) event, or even 6 different events.  SAX 1 itself ignores CDATA sections, so these possibilities are the same regardless.

SAX2 allows you to receive lexical events, including CDATA section boundaries, but this is an option you turn on.  If you don't, considerations are the same as above (except, of course, that the SAX2 characters event just transmits the text object rather than a chunk of text plus offsets.

In short:

In SAX1, no guarantees of how you get character events, though you're probably right in practice for most parsers

In SAX2, same as SAX1 unless you ask for lexical events, in which case you get at least 3 events in the case you mentioned, and possibly more.


-- 
Uche Ogbuji                               Principal Consultant
uche.ogbuji@f...               +1 720 320 2046
Fourthought, Inc.                         http://Fourthought.com 
4735 East Walnut St, Boulder, CO 80301-2537, USA
XML strategy, XML tools (http://4Suite.org), knowledge management




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.