Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 25th, 2006, 10:55 AM
christophe_usenet@yahoo.fr
Guest
 
Posts: n/a
Default Problem with Xerces-C SAX parser ?

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

--
Christophe

 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles