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;
	}
Exemplo n.º 2
0
void XMLDocumentParser::startDocument()
{
    initializeParserContext();
    ExceptionCode ec = 0;

    if (!m_parsingFragment) {
        document()->setXMLStandalone(m_stream.isStandaloneDocument(), ec);

        QStringRef version = m_stream.documentVersion();
        if (!version.isEmpty())
            document()->setXMLVersion(version, ec);
        QStringRef encoding = m_stream.documentEncoding();
        if (!encoding.isEmpty())
            document()->setXMLEncoding(encoding);
    }
}
Exemplo n.º 3
0
void XMLDocumentParser::startDocument()
{
    initializeParserContext();

    if (!m_parsingFragment) {
        document()->setXMLStandalone(m_stream.isStandaloneDocument(), IGNORE_EXCEPTION);

        QStringRef version = m_stream.documentVersion();
        if (!version.isEmpty())
            document()->setXMLVersion(version, IGNORE_EXCEPTION);
        QStringRef encoding = m_stream.documentEncoding();
        if (!encoding.isEmpty())
            document()->setXMLEncoding(encoding);
        document()->setHasXMLDeclaration(!version.isEmpty());
    }
}
	bool LibxmlSaxParser::parseFile( const char* fileName )
	{
			mParserContext = xmlCreateFileParserCtxt(fileName);

			if ( !mParserContext )
			{
				ParserError error(ParserError::SEVERITY_CRITICAL,
						ParserError::ERROR_COULD_NOT_OPEN_FILE,
						0,
						0,
						0,
						0,
						fileName);
				getParser()->getErrorHandler()->handleError(error);
				return false;
			}

			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;
	}