Reputation: 161
i am using xerces 3 in my c++ program . i would like some one to guide me , how to extract text between start and end tag in sax parsing . for example , suppose we have :
<?xml version="1.0"?>
<catalog>
<book id="123">
<author>Introduction to algorithm </author>
</book>
</catalog>
how to access this text : 'Introduction to algorithm'
Upvotes: 3
Views: 2333
Reputation: 1
Use the override keyword at your methods. This might help you a little bit
Upvotes: -1
Reputation: 28882
You should be able to use:
void HandlerBase::characters ( const XMLCh *const chars,
const XMLSize_t length
)
Just be aware that this might be called numerous times.
Upvotes: 2
Reputation: 19767
If I remember correctly, you write your own handler inheriting from HandlerBase
. startElement()
will be called at <author>
and then endElement()
will be called at </author>
. All text in between will be passed to characters()
, so you need to know when you are inside <author></author>
, and make use of this to save the characters to a useful place inside your characters()
function: http://xerces.apache.org/xerces-c/apiDocs-3/classHandlerBase.html
When I did this (some time ago) I just cheated and had everything as attributes, which are passed in to startElement()
and saves a lot of hassle.
EDIT: I made my own example and had the same problem (which you didn't describe well in the question, and would have been easier to work out if you'ld provided your code, by the way). Look at the documentation (note I wasn't careful about checking which version, but still):
virtual void characters (const XMLCh *const chars, const XMLSize_t length)
Then check the actual header file.
virtual void characters
(
const XMLCh* const chars
, const unsigned int length
);
Spot the difference? Make your own version's signature match the header file, it will work.
Upvotes: 1