Hi!
Well, that's more or less exactly what I want to do as well. Since I use
SAX2XMLReader my handlerclass inherits from DefaultHandler. DefaultHandler is
used with the SAX2-api and HandlerBase is used with SAX as far as I know from
the docs. Anyway, they both provide an empty implementation for handlers.
My handler class looks something like this:
class TestAppHandler : public DefaultHandler
{
public:
TestAppHandler ();
virtual ~TestAppHandler();
//
// SAX-functions (three over loaded functions. The others are empty
(implemented in DefaultHandler))
//
void startElement(const XMLCh* const uri,
const XMLCh* const localname,
const XMLCh* const qname,
const Attributes& attributes);
void endElement(const XMLCh* const uri,
const XMLCh* const localname,
const XMLCh* const qname);
void characters(const XMLCh *const chars, const unsigned int length);
private:
const XMLCh* functionString;
const XMLCh* argString;
};
and the implementation of endElement() looks like:
void TestAppHandler::endElement(const XMLCh* const uri,
const XMLCh* const localname,
const XMLCh* const qname)
{
std::cout << "TestAppHandler::endElement(): " <<
XMLString::transcode(localname) << std::endl;
if (XMLString::equals(localname, functionString)) {
//
// do something (functionsString is defined in constructor)
//
}
if (XMLString::equals(localname, argString)) {
//
// do something else (argString is defined in constructor)
//
}
}
I use to parse a file with function names and arguments and then call the
correct function with the supplied arguments (for automatic regression tests).
The endElement() really works fine. Whenever an </argument> is encountered an
argument is stored and when </function> is encountered the function is called
with all arguments.
What I am trying to say is that endElement() should be available in
DefaultHandler as well. There must be something else that's wrong.
//daniel
David --- (2004-03-16 10:59):
>Hi daniel,
>For instance I'm using xerces_2_4.
>
>You are using DefaultHandler and I'm trying to use
>handlerbase. The reason for that is the following
>method EndElement. It doesn't display anything in my
>case. However start element display properly all the
>elements.
>My idea is only to display some elements, not all of
>the elements that are found in the file that's why i
>want to modify endElement.
>If I use DefaultHandler it runs but still endElement
>is not displayed. Did you try to display the
>endElement like below?
>
>void Xml::endElement(const XMLElementDecl & elemDecl,
>const unsigned int urlId, const bool isRoot, const
>XMLCh *const elemPrefix)
>{
>
> std::cout << "Found end element:" <<
>XMLString::transcode(elemPrefix) << std::endl;
>
>}
>
>
>--- Gr�ndal_Daniel <[EMAIL PROTECTED]> a �crit
>: > Hi!
>>
>> I'm doing roughly the same thing as you are:
>>
>> ----------------------------------------------
>> class TestAppHandler : public DefaultHandler
>> {
>> public:
>> TestAppHandler ();
>> virtual ~TestAppHandler();
>> void startElement(const XMLCh* const uri,
>> const XMLCh* const localname,
>> const XMLCh* const qname,
>> const Attributes& attributes);
>> void endElement(const XMLCh* const uri,
>> const XMLCh* const localname,
>> const XMLCh* const qname);
>> void characters(const XMLCh *const chars, const
>> unsigned int length);
>> -----------------------------------------------
>>
>> I have no problem over loading the function
>> endElement() and then to register
>> an object of type TestAppHandler as a
>> contenthandler.
>>
>> ---------------------------------------------
>> parser = XMLReaderFactory::createXMLReader();
>> TestAppHandler handler;
>> parser->setContentHandler(&handler);
>> --------------------------------------------
>>
>> I use Xerces 2.3.0 if that should matter?
>>
>> //daniel
>>
>>
>>
>> David --- (2004-03-16 00:17):
>> >Hello,
>> >Going through the doc i noticed that EndElement
>> >requires the implementation of a handlerbase.
>> >However when I use a handlerbase in my code in got
>> an
>> >error while using SAX2XMLREADER. It complains that
>> >setContentHandler requires a contenthandler.
>> However
>> >my XMLhandler is a HandlerBase.
>> >If I use DefaultHandler instead of HandleBase in
>> Xml.h
>> >it works but then the endElement method is not
>> >available. Can anybody help??
>> >
>> >Error at execution:
>> >
>> >[EMAIL PROTECTED]:XmlXercesFactory>make
>> >g++ Xml.cpp -c -o Xml.o
>> >g++ SaxParser.cpp -c -o SaxParser.o
>> >SaxParser.cpp: In member function `virtual void
>> >SaxParser::ParseFile(char*)':
>> >SaxParser.cpp:58: error: no matching function for
>> call
>> >to `
>> >
>>
>>xercesc_2_4::SAX2XMLReader::setContentHandler(Xml*)'
>>
>>/usr/local/include/xercesc/sax2/SAX2XMLReader.hpp:304:
>> >error: candidates are:
>> > virtual void
>> >
>>
>>xercesc_2_4::SAX2XMLReader::setContentHandler(xercesc_2_4::ContentHandler*)
>> >make: *** [SaxParser.o] Error 1
>> >>
>> >
>> >#FILES#
>> >
>> >#Xml.h
>> >
>> >
>> >class xml : public HandlerBase {
>> >
>> >public:
>> >Xml()
>> >virtual ~Xml()
>> >
>> >###Here all the handler methods
>> >
>> >}
>> >
>> >#
>> >in SaxParser.cpp
>> >void SaxParser::ParseFile(char *xmlFile)
>> >{
>> > std::cout <<"Trying to parse "<< xmlFile <<
>> "..."
>> ><< std::endl;
>> >
>> > Xml handler;
>> >
>> > c_parser->setErrorHandler(&handler);
>> > c_parser->setContentHandler(&handler);
>> >
>> >
>> > try {
>> > c_parser->parse(xmlFile);
>> > }
>> > catch (XMLException &e){
>> > std::cout << "Error parsing file "<<
>> >Error(e.getMessage()) << std::endl;
>> > exit (-1);
>> > }
>> > ....
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >Yahoo! Mail : votre e-mail personnel et gratuit qui
>> vous suit partout !
>> >Cr�ez votre Yahoo! Mail sur
>> http://fr.benefits.yahoo.com/
>> >
>> >Dialoguez en direct avec vos amis gr�ce � Yahoo!
>> Messenger !T�l�chargez Yahoo!
>> Messenger sur http://fr.messenger.yahoo.com
>> >
>>
>>---------------------------------------------------------------------
>> >To unsubscribe, e-mail:
>> [EMAIL PROTECTED]
>> >For additional commands, e-mail:
>> [EMAIL PROTECTED]
>> >
>>
>>
>__________________________________________________________
>> RFV Data/Produktenheten E-post:
>> [EMAIL PROTECTED]
>> Daniel Gr�ndal Tfn: 060-187126
>> S:a J�rnv�gsgatan 41 Mobil: 070-3016517
>> 851 93 Sundsvall Fax: 060-147870
>>
>__________________________________________________________
>>
>>
>>
>>
>---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> [EMAIL PROTECTED]
>> For additional commands, e-mail:
>> [EMAIL PROTECTED]
>>
>
>
>
>
>
>
>Yahoo! Mail : votre e-mail personnel et gratuit qui vous suit partout !
>Cr�ez votre Yahoo! Mail sur http://fr.benefits.yahoo.com/
>
>Dialoguez en direct avec vos amis gr�ce � Yahoo! Messenger !T�l�chargez Yahoo!
Messenger sur http://fr.messenger.yahoo.com
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
__________________________________________________________
RFV Data/Produktenheten E-post: [EMAIL PROTECTED]
Daniel Gr�ndal Tfn: 060-187126
S:a J�rnv�gsgatan 41 Mobil: 070-3016517
851 93 Sundsvall Fax: 060-147870
__________________________________________________________
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]