Hi,

I wrote an implementation of DOMErrorHandler::handleError(). This returns 
false on fatal errors like a missing closing tag. But the parsing of the file 
is not aborted and I did not get an error from parser->parseURI(). What do I 
have to do, to let the main program abort at fatal errors?

Here is the implementation of DOMErrorHandler:

class XmldbErrorHandler : public DOMErrorHandler {
public:  // --- public methods ---
        //! Default constructor.
        XmldbErrorHandler() {};
        //! Destructor.
        ~XmldbErrorHandler() {};
        //! Reaction on a parser error.
        bool handleError(const DOMError& domError) {
                std::ostringstream errMsg;
    switch ( domError.getSeverity() ) {
                case DOMError::DOM_SEVERITY_WARNING:
        errMsg << "Warning at file ";
        break;
                case DOMError::DOM_SEVERITY_ERROR:
        errMsg << "Error at file ";
        break;
                case DOMError::DOM_SEVERITY_FATAL_ERROR:
                default:
        errMsg << "Fatal Error at file ";
    };
    
    errMsg << XercesString(domError.getLocation()->getURI()).stdStr()
         << ", line " << domError.getLocation()->getLineNumber()
         << ", char " << domError.getLocation()->getColumnNumber()
         << " : " << XercesString(domError.getMessage()).stdStr();

    switch ( domError.getSeverity() ) {
                case DOMError::DOM_SEVERITY_WARNING:
                case DOMError::DOM_SEVERITY_ERROR:
                        d4trace << errMsg.str() << std::endmsg;
                        return true;
                case DOMError::DOM_SEVERITY_FATAL_ERROR:
            d4err << errMsg.str() << std::endmsg;
            return false;
                default:
                        d4err << "XML parser: Unknown severity" << std::endmsg;
                        break;
                }
                return false;
        }
private:  // --- private attributes ---
};  // ### class XmldbErrorHandler ###

Thanks, Sven

Reply via email to