SAX XML Parser

This is a discussion on SAX XML Parser within the C++ Programming forums, part of the General Programming Boards category; Hi, I am using VS 2005 and trying to implement the Xerces-C++ parser. Everything is linked and compiles ok - ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    35

    Angry SAX XML Parser

    Hi,

    I am using VS 2005 and trying to implement the Xerces-C++ parser.
    Everything is linked and compiles ok - I am using the example supplied (below).
    When I run it I get a runtime unhandled error exception and the program terminates. This happens on the line parse->parse(xmlFile).

    Anyone sucessfully used this? Any help would be appreciated.

    Thanks

    Mike

    Code:
    #include <xercesc/parsers/SAXParser.hpp>
        #include <xercesc/sax/HandlerBase.hpp>
        #include <xercesc/util/XMLString.hpp>
    
        #include <iostream>
    
        using namespace std;
        using namespace xercesc;
    
        int main (int argc, char* args[]) {
    
            try {
                XMLPlatformUtils::Initialize();
            }
            catch (const XMLException& toCatch) {
                char* message = XMLString::transcode(toCatch.getMessage());
                cout << "Error during initialization! :\n"
                     << message << "\n";
                XMLString::release(&message);
                return 1;
            }
    
            char* xmlFile = "x1.xml";
            SAXParser* parser = new SAXParser();
            parser->setDoValidation(true);
            parser->setDoNamespaces(true);    // optional
    
            DocumentHandler* docHandler = new HandlerBase();
            ErrorHandler* errHandler = (ErrorHandler*) docHandler;
            parser->setDocumentHandler(docHandler);
            parser->setErrorHandler(errHandler);
    
            try {
                parser->parse(xmlFile);
            }
            catch (const XMLException& toCatch) {
                char* message = XMLString::transcode(toCatch.getMessage());
                cout << "Exception message is: \n"
                     << message << "\n";
                XMLString::release(&message);
                return -1;
            }
            catch (const SAXParseException& toCatch) {
                char* message = XMLString::transcode(toCatch.getMessage());
                cout << "Exception message is: \n"
                     << message << "\n";
                XMLString::release(&message);
                return -1;
            }
            catch (...) {
                cout << "Unexpected Exception \n" ;
                return -1;
            }
    
            delete parser;
            delete docHandler;
            return 0;
        }

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    I don't know the library, but my guess is that 'parse' expects the actual data (not the file name). It is odd that the exception isn't caught before the last handler, though. Look into the exception hierarchy and make sure there isn't a more basic handler...
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 11-30-2006, 07:04 AM
  2. XML Parser
    By Hexxx in forum C++ Programming
    Replies: 1
    Last Post: 03-30-2006, 06:52 PM
  3. Problem with a file parser.
    By Hulag in forum C++ Programming
    Replies: 7
    Last Post: 03-17-2005, 08:54 AM
  4. xml parser: recommendations?
    By captain-cat in forum C Programming
    Replies: 1
    Last Post: 07-26-2004, 09:54 AM
  5. Problem with Apache XML C++ Parser library
    By gandalf_bar in forum C++ Programming
    Replies: 2
    Last Post: 07-21-2004, 09:42 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21