Thread: SAX XML Parser

  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,708
    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:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 11-30-2006, 08:04 AM
  2. XML Parser
    By Hexxx in forum C++ Programming
    Replies: 1
    Last Post: 03-30-2006, 07:52 PM
  3. Problem with a file parser.
    By Hulag in forum C++ Programming
    Replies: 7
    Last Post: 03-17-2005, 09: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