OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help



   Re: [xml-dev] CDATA vs. Escaped characters

[ Lists Home | Date Index | Thread Index ]

> 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.


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@fourthought.com               +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


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS