bool LibxmlSaxParser::parseBuffer( const char* uri, const char* buffer, int length ) { mParserContext = xmlCreateMemoryParserCtxt( buffer, length ); if ( !mParserContext ) { ParserError error(ParserError::SEVERITY_CRITICAL, ParserError::ERROR_COULD_NOT_OPEN_FILE, 0, 0, 0, 0, uri); IErrorHandler* errorHandler = getParser()->getErrorHandler(); if ( errorHandler ) { errorHandler->handleError(error); } return false; } // We let libxml replace the entities mParserContext->replaceEntities = 1; if (mParserContext->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler) { xmlFree(mParserContext->sax); } mParserContext->sax = &SAXHANDLER; mParserContext->userData = (void*)this; initializeParserContext(); xmlParseDocument(mParserContext); mParserContext->sax = 0; if ( mParserContext->myDoc ) { xmlFreeDoc(mParserContext->myDoc); mParserContext->myDoc = 0; } xmlFreeParserCtxt(mParserContext); mParserContext = 0; return true; }
//-------------------------------------------------------------------- bool ParserTemplateBase::handleError( ParserError::Severity severity, ParserError::ErrorType errorType, StringHash elementHash, StringHash attributeHash, const ParserChar* additionalText /*= ""*/ ) { IErrorHandler* errorHandler = getErrorHandler(); if ( !errorHandler ) return (severity == ParserError::SEVERITY_CRITICAL) ? true : false; ParserError error(severity, errorType, getNameByStringHash(elementHash), getNameByStringHash(attributeHash), getLineNumber(), getColumnNumber(), additionalText ? (const char*)additionalText : ""); bool handlerWantsToAbort = errorHandler->handleError(error); return (severity == ParserError::SEVERITY_CRITICAL) ? true : handlerWantsToAbort; }