[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: eXpat - Converting character data and losing spaces



Hi Bob,

The only flaw I can see is that you only retain the data from the LAST 
call to the character data handler.  If it's called repeatedly for the 
same XML element, you discard anything from previous calls.

I typically concatenate the data.  For example, I might create a stack:

    D stackval        s            512C   varying dim(32)

start elem handler:

        depth = depth + 1;
        stackval(depth) = %ucs2('');

characterr data handler:

        stackval(depth) = stackval(depth) + %subst(string:1:len);

end elem handler:

         if elemName = 'CustAddr';
               custaddr = %char(stackval(depth));
         endif;
         depth = depth - 1;

So basically I clear the data for the current element in the start 
handler, then every time the character data handler is called, I add the 
new data to the end of what I've received previously.  That way, it can be 
called many times without lsoing anything.  Finally, when the end handler 
is called, I know I have all of the data, so I save it to a variable.

-- 
Scott Klement  http://www.scottklement.com

On Tue, 23 Jan 2007, Bob Barnhart wrote:

> Hello,
>    I'm pasting the code that I'm using for my characher data handler in
> eXpat.  The problem is that if the character data contains leading spaces,
> they are not all preserved after converting from UCS-2 to type character in
> the last line.  Everything seems to work fine if there are no leading
> spaces, and spaces within the data are preserved.  But leading spaces cause
> problems.  It may just be a coincidence, but the number of leading spaces
> seems to be cut in half when it's converted to type character.  Does anyone
> know why this is happening?
>
> Thanks!
> Bob Barnhart
> Fremont Insurance Company
>
>
>
> //=====================================================================
> // character data handler
> //=====================================================================
> P chardata             B
> D chardata             PI
> D   d                                               likeds(stack)
> D   string                          16383C   const options(*varsize)
> D   len                                   10I  0 value
> D data                   s         16383a    varying
>
> /free
> if (len < 1);
> return;
> endif;
>
> data = %char(%subst(string:1:len));
> ....
>
>
>
>
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------