Problem with Xerces-C SAX parser ?

C

christophe_usenet

Hi,

I'm new to XML, and i'm trying to make a dummy SAX parser with Xerces-C
2.6.0-3.
Unfortunately, though it compiles, it does not produce any output :-(
Here is the code:

[XMLParser.cc]-----------------------------------------------------------------------------

#include <xercesc/parsers/SAXParser.hpp>
#include <xercesc/sax/HandlerBase.hpp>
#include <xercesc/util/XMLString.hpp>

#include <iostream>

XERCES_CPP_NAMESPACE_USE

using namespace std;


class MySAXHandler : public HandlerBase {
public:
void startElement(const XMLCh* const, AttributeList&);
void fatalError(const SAXParseException&);
};

void
MySAXHandler::startElement(const XMLCh* const name,
AttributeList& attributes)
{
char* message = XMLString::transcode(name);
cout << "I saw element: "<< message << endl;
XMLString::release(&message);
}

void
MySAXHandler::fatalError(const SAXParseException& exception)
{
char* message = XMLString::transcode(exception.getMessage());
cout << "Fatal Error: " << message
<< " at line: " << exception.getLineNumber()
<< endl;
}


int main (int argc, char* args[]) {

XMLPlatformUtils::Initialize();

char* xmlFile = "./test.xml";
SAXParser* parser = new SAXParser();

DocumentHandler* docHandler = new MySAXHandler();
ErrorHandler* errHandler = (ErrorHandler*) docHandler;
parser->setDocumentHandler(docHandler);
parser->setErrorHandler(errHandler);

parser->parse(xmlFile);

delete parser;
delete docHandler;
return 0;
}

-----------------------------------------------------------------------------------------------


I compile it with

g++ -o xml_parser XMLParser.cc -lxerces-c

I probably miss something, but i don't see what ?

Thanks a lot for your help :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top