[Expat-discuss] CRLF conversion question

Karl Waclawek karl at waclawek.net
Thu Sep 9 15:10:00 CEST 2004


----- Original Message ----- 
From: "Armin Bauer" <armin.bauer at desscon.com>
Sent: Thursday, September 09, 2004 8:55 AM

> On Wed, 2004-09-08 at 00:35, Fred L. Drake, Jr. wrote:
> > On Tuesday 07 September 2004 06:18 pm, Armin Bauer wrote:
> >  > Sorry if its me being stupid but why do CDATA sections contain nodes at
> >  > all? As far as my understanding goes the parser has not to touch the
> >  > cdata section at all.
> >
> > The node structure is defined by whatever API is providing you with nodes
> > (Expat isn't).  If you're using a DOM with wbxml (or if wbxml is using a DOM
> > internally), that's why nodes are used.
> >
> > Line-end normalization is required at all times, even inside CDATA marked
> > sections.  CDATA marked sections are not intended as an escape hatch for
> > binary data.
> >
>
> Thats true. But is not xml compliant to do line-end normalization in
> cdata sections.
>
> Definition of a cdata section:
>
> [18]   CDSect   ::=   CDStart CData
> CDEnd[19]   CDStart   ::=   '<![CDATA['
> [20]   CData   ::=   (Char* - (Char* ']]>' Char*))
> [21]   CDEnd   ::=   ']]>'
>
> as taken from http://www.w3.org/TR/REC-xml/#sec-cdata-sect
> Notice the Char*.
>
> Char is defined as:
>
> Char   ::=   #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] |
> [#x10000-#x10FFFF]
> /* any Unicode character, excluding the surrogate blocks, FFFE, and
> FFFF. */
>
> as taken from http://www.w3.org/TR/REC-xml/#NT-Char. And this clearly
> include 0x0a and 0x0d. So expat should never touch these characters.

But if you read this section, it becomes clear that it has to touch them
(the important words are in upper case):

2.11 End-of-Line Handling
XML parsed entities are often stored in computer files which, for editing convenience, are organized
into lines. These lines are typically separated by some combination of the characters CARRIAGE
RETURN (#xD) and LINE FEED (#xA).

To simplify the tasks of applications, the XML processor MUST behave as if it normalized all line
breaks in external parsed entities (including the document entity) ON INPUT, BEFORE PARSING, by
translating both the two-character sequence #xD #xA and any #xD that is not followed by #xA to a
single #xA character.



Karl



More information about the Expat-discuss mailing list