expat whitespace in CDATA sections

Discussion in 'XML' started by Chris Waddingham, Mar 3, 2004.

  1. I am experiencing 2 problems with CDATA sections. These are:

    1. Expat appears to be collapsing adjacent linefeeds into one inside CDATA
    sections.
    2. Expat (XML_CharacterDataHandler) returns the wrong len value for CDATA
    sections containing ']'.

    I would be grateful of any help you can offer.

    My XML application contains code like this:

    <![CDATA[
    namespace
    {
    int max=10;

    unsigned char buffer[10];
    ]]>

    My C++ character_data_handler looks like this - note in particular the cout
    diagnostic:

    void character_data_handler( const XML_Char* s, int len )
    {
    if ( m_element_data != "" )
    {
    m_element_data += "\n";
    }

    cout << "s=" << s << ", len=" << len << endl;
    if ( len == 0 )
    {
    m_element_data += "\n";
    }
    else
    {
    m_element_data.append( s, len );
    }
    }

    My problems are that character_data_handler returns the following:

    <![CDATA[
    namespace
    {
    int max=10;
    unsigned char buffer[10
    ];
    ]]>

    As you can see line 5 is lost and line 6 is broken at the ']'.

    The diagnostic output from character_data_handler is:

    s=namespace, len=9
    s={, len=1
    s= int max=10;, len=15
    s= unsigned char buffer[10];, len=27
    s=];, len=2

    Best regards,

    Chris.
     
    Chris Waddingham, Mar 3, 2004
    #1
    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. Janne
    Replies:
    0
    Views:
    1,776
    Janne
    Nov 11, 2003
  2. Arvin Portlock
    Replies:
    0
    Views:
    397
    Arvin Portlock
    Feb 26, 2004
  3. Raman
    Replies:
    6
    Views:
    4,729
    santosh
    Aug 3, 2007
  4. sharan
    Replies:
    1
    Views:
    721
    Pavel Lepin
    Oct 26, 2007
  5. Sohni

    Parsing cdata using expat in C

    Sohni, Mar 27, 2012, in forum: C Programming
    Replies:
    0
    Views:
    661
    Sohni
    Mar 27, 2012
Loading...

Share This Page