Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > C++ SAX Parser ---handling special characters

Reply
Thread Tools

C++ SAX Parser ---handling special characters

 
 
mamatha.kumar@gmail.com
Guest
Posts: n/a
 
      04-17-2007
Hi

My xml is as follows

<?xml version="1.0" encoding="UTF-8"?>
<StreetName>A &amp; B</StreetName>

But when I parse the xml using the characters fn of C++ SAX Xerces
parser(OS: solaris) , written below

characters( const XMLCh* const chars, const unsigned int leng
th)
{
string value = XMLString::transcode(chars);

if (currentElement=="")
return;

if (currentElement=="StreetName")
cout << "The StreetName is " << value << endl;

}

The output is
The StreetName is A
The StreetName is & B

Why is this happening instead of getting the StreetName as A & B.
What is the mistake am making ?
Any help is appreciated.

Thanks
Kumar.

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      04-17-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> The output is
> The StreetName is A
> The StreetName is & B
>
> Why is this happening instead of getting the StreetName as A & B.
> What is the mistake am making ?


You seem to expect that the parser pushes the full contents of an
element into your characters handler but it is not required to do so, it
can break up character data into chunks and call the characters handler
several times. So your SAX client application needs to take care of that
and store the character data somewhere and concatenate if you need that.




--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
Joseph Kesselman
Guest
Posts: n/a
 
      04-17-2007
For parser efficiency reasons, SAX does not promise to deliver
contiguous text as a single characters() events. If you need it all in
one string, it's your responsibility as a SAX handler author to do your
own buffering, and defer processing until the next non-characters()
event comes in (indicating end of text).

A good SAX tutorial really should have explained this; it's the single
most common beginner mistake in SAX.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
java sax parser special characters shivaraj Java 3 07-07-2008 05:41 AM
Remove only special characters and junk characters from a file rvino Perl 0 08-14-2007 07:23 AM
Re: Meta-Characters, Special Characters xah@xahlee.org Java 2 05-31-2007 09:25 AM
How to convert HTML special characters to the real characters with a Java script Stefan Mueller HTML 3 07-23-2006 10:09 PM
SAX parser: problems with overwritten characters method leo Java 1 04-13-2005 02:26 PM



Advertisments