ASCII control characters in CDATA section

Discussion in 'XML' started by nowhere@home.com, Nov 27, 2003.

  1. Guest

    Hi,

    I need to preserve some ASCII control characters (CR and LF) within an
    XML file so I have included the data in a CDATA section. However,
    when parsing it using expat, I lose the CR characters.

    My question is: Should I be using a different character set (not
    UTF-8) or is this a bug in expat?

    TIA, Mark
    , Nov 27, 2003
    #1
    1. Advertising

  2. wrote:
    > I need to preserve some ASCII control characters (CR and LF) within an
    > XML file so I have included the data in a CDATA section. However,
    > when parsing it using expat, I lose the CR characters.
    >
    > My question is: Should I be using a different character set (not
    > UTF-8) or is this a bug in expat?


    I don't think so, with XML all line endings are normalized
    http://www.w3.org/TR/REC-xml#sec-line-ends
    so even a CDATA section doesn't help to preserve a carriage return


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Nov 27, 2003
    #2
    1. Advertising

  3. In article <>,
    <> wrote:

    >I need to preserve some ASCII control characters (CR and LF) within an
    >XML file so I have included the data in a CDATA section. However,
    >when parsing it using expat, I lose the CR characters.


    To preserve CRs, you need to use character references (
    ), because
    CR and CR-LF are normalized to LF when an XML document is read.

    You can't use character references in a CDATA section, so it's
    probably better to forget about CDATA and just escape any characters
    that need it. The main use for CDATA is preserving human readability
    of text that includes < and & characters, such as XML examples inside
    an XML document. It doesn't really work for arbitrary data.

    -- Richard
    --
    Spam filter: to mail me from a .com/.net site, put my surname in the headers.

    FreeBSD rules!
    Richard Tobin, Nov 27, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Davison
    Replies:
    1
    Views:
    562
    Hal Rosser
    Jul 7, 2004
  2. CarlosRivera
    Replies:
    5
    Views:
    778
    CarlosRivera
    Jan 16, 2005
  3. Tak Sze
    Replies:
    2
    Views:
    4,237
    Patrick TJ McPhee
    Apr 30, 2004
  4. Replies:
    3
    Views:
    728
    Joe Kesselman
    Mar 6, 2006
  5. Alextophi
    Replies:
    8
    Views:
    473
    Alan J. Flavell
    Dec 30, 2005
Loading...

Share This Page