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
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