当前位置: 首页>>代码示例>>C++>>正文


C++ SAX2XMLReader::parse方法代码示例

本文整理汇总了C++中SAX2XMLReader::parse方法的典型用法代码示例。如果您正苦于以下问题:C++ SAX2XMLReader::parse方法的具体用法?C++ SAX2XMLReader::parse怎么用?C++ SAX2XMLReader::parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SAX2XMLReader的用法示例。


在下文中一共展示了SAX2XMLReader::parse方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main


//.........这里部分代码省略.........
        usage();
        return 1;
    }

    // Initialize the XML4C2 system
    try
    {
        if (strlen(localeStr))
        {
            XMLPlatformUtils::Initialize(localeStr);
        }
        else
        {
            XMLPlatformUtils::Initialize();
        }

        if (recognizeNEL)
        {
            XMLPlatformUtils::recognizeNEL(recognizeNEL);
        }
    }

    catch (const XMLException& toCatch)
    {
        XERCES_STD_QUALIFIER cerr << "Error during initialization! Message:\n"
            << StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
        return 1;
    }

    //
    //  Create a SAX parser object. Then, according to what we were told on
    //  the command line, set it to validate or not.
    //
    SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
    parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, doNamespaces);
    parser->setFeature(XMLUni::fgXercesSchema, doSchema);
    parser->setFeature(XMLUni::fgXercesSchemaFullChecking, schemaFullChecking);
    parser->setFeature(XMLUni::fgXercesIdentityConstraintChecking, identityConstraintChecking);
    parser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, namespacePrefixes);

    if (valScheme == SAX2XMLReader::Val_Auto)
    {
        parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
        parser->setFeature(XMLUni::fgXercesDynamic, true);
    }
    if (valScheme == SAX2XMLReader::Val_Never)
    {
        parser->setFeature(XMLUni::fgSAX2CoreValidation, false);
    }
    if (valScheme == SAX2XMLReader::Val_Always)
    {
        parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
        parser->setFeature(XMLUni::fgXercesDynamic, false);
    }

    //
    //  Create our SAX handler object and install it on the parser, as the
    //  document and error handler.
    //
    SAX2CountHandlers handler;
    parser->setContentHandler(&handler);
    parser->setErrorHandler(&handler);

    //
    //  Get the starting time and kick off the parse of the indicated
    //  file. Catch any exceptions that might propogate out of it.
开发者ID:ksmyth,项目名称:xerces-c,代码行数:67,代码来源:SAX2Count.cpp

示例2: parse

//------------------------------------------------------------------------
//
//  parse   - This is the method that is invoked by the rest of
//            the test program to actually parse an XML file.
//
//------------------------------------------------------------------------
int ThreadParser::parse(int fileNum)
{
    MemBufInputSource *mbis = 0;
    InFileInfo        *fInfo = &gRunInfo.files[fileNum];
    bool              errors = false;

    fCheckSum = 0;

    if (gRunInfo.inMemory) {
        mbis = new  MemBufInputSource((const XMLByte *) fInfo->fileContent,
                                       fInfo->fileSize,
                                       fInfo->uFileName,
                                       false);
    }

    try
    {
        if (gRunInfo.dom) {
            // Do a DOM parse
            fXercesDOMParser->resetDocumentPool();
            if (gRunInfo.inMemory)
                fXercesDOMParser->parse(*mbis);
            else
                fXercesDOMParser->parse(fInfo->fileName);
            fDoc = fXercesDOMParser->getDocument();
            domCheckSum(fDoc);
        }
        else if (gRunInfo.sax) {
            // Do a SAX1 parse
            if (gRunInfo.inMemory)
                fSAXParser->parse(*mbis);
            else
                fSAXParser->parse(fInfo->fileName);
        }
        else {
            // Do a SAX2 parse
            if (gRunInfo.inMemory)
                fSAX2Parser->parse(*mbis);
            else
                fSAX2Parser->parse(fInfo->fileName);
        }
    }
    catch (const OutOfMemoryException&)
    {
	    fprintf(stderr, " during parsing: %s\n OutOfMemoryException.\n", fInfo->fileName);        
	    errors = true;
    }
    catch (const XMLException& e)
    {
        char *exceptionMessage = XMLString::transcode(e.getMessage());
        fprintf(stderr, " during parsing: %s\n Exception message is: %s\n",
            fInfo->fileName, exceptionMessage);
        XMLString::release(&exceptionMessage);
        errors = true;
    }
    catch (const DOMException& toCatch)
    {
        fprintf(stderr, " during parsing: %s\n DOMException code is: %i\n",
            fInfo->fileName, toCatch.code);
        errors = true;
    }
    catch (const SAXParseException& e)
    {
        char *exceptionMessage = XMLString::transcode(e.getMessage());
        fprintf(stderr, " during parsing: %s\n Exception message is: %s\n",
            fInfo->fileName, exceptionMessage);
        XMLString::release(&exceptionMessage);
        errors = true;
    }
    catch (...)
    {
        fprintf(stderr, "Unexpected exception during parsing\n");
        errors = true;
    }

    delete mbis;
    if (errors) {
        fflush(stderr);
        return 0;  // if errors occurred, return zero as if checksum = 0;
    }
    return fCheckSum;
}
开发者ID:xin3liang,项目名称:platform_external_xerces-cpp,代码行数:88,代码来源:ThreadTest.cpp

示例3:

bool amis::io::XercesSaxParseBase::parseFile(const ambulant::net::url* filepath)
{
	SAX2XMLReader* parser;
	mFilepath = *filepath;
	mError.clear();
	amis::util::Log::Instance()->writeMessage("Parsing file: ", filepath, "XercesSaxParseBase::parseFile");
	//try-catch block for Xerces platform utilities
	try
	{
		XMLPlatformUtils::Initialize();
	}
	
	catch (const XMLException& toCatch)
	{
		mError.setCode(amis::PARSE_ERROR);
		char *msg = XMLString::transcode(toCatch.getMessage());
		string str;
		str.assign(msg);	
		mError.setMessage(str);
		XMLString::release(&msg);
		amis::util::Log::Instance()->writeError(mError, "XercesSaxParseBase::parseFile");
		return false;
	}
		
	//assuming we've made it this far, create a new parser
	parser = XMLReaderFactory::createXMLReader();

	//set these parser features to turn off DTD loading and validation
	parser->setFeature(XMLUni::fgXercesLoadExternalDTD, false);
	parser->setFeature(XMLUni::fgSAX2CoreValidation, false);
	
	amis::io::UrlInputSource* p_input_source = amis::io::NewUrlInputSource(mFilepath);
	if (p_input_source == NULL)
	{
		mError.setCode(amis::PARSE_ERROR);
		string str;
		str.assign("Could not create input source for " + mFilepath.get_url());	
		mError.setMessage(str);
		delete p_input_source;
		delete parser;
		XMLPlatformUtils::Terminate();
		amis::util::Log::Instance()->writeError(mError, "XercesSaxParseBase::parseFile");
		return false;
	}

	//try-catch block for Xerces parsing
	try 
	{
		//give the sax parser pointers to our content and error handler object
		parser->setContentHandler(this);
		parser->setErrorHandler(this);
		//parser begins parsing; expect SAX Events soon
		parser->parse((*p_input_source));
	}
	
	catch (const XMLException& toCatch)
	{	
		mError.setCode(amis::PARSE_ERROR);
		char *msg = XMLString::transcode(toCatch.getMessage());
		string str;
		str.assign(msg);	
		mError.setMessage(str);
		XMLString::release(&msg);
		delete p_input_source;
		delete parser;
		XMLPlatformUtils::Terminate();
		amis::util::Log::Instance()->writeError(mError, "XercesSaxParseBase::parseFile");
		return false;
	}
	
	delete p_input_source;
	delete parser;

	try
	{
		XMLPlatformUtils::Terminate();
	}
	catch (...)//const XMLException& toCatch)
	{
		amis::util::Log::Instance()->writeWarning("Exception while terminating XMLPlatformUtils", 
			"XercesSaxParseBase::parseFile");
	}

	if (mError.getCode() != amis::OK) return false;
	amis::util::Log::Instance()->writeMessage("Done parsing.", "XercesSaxParseBase::parseFile");
	return true;

}
开发者ID:daisy,项目名称:amis,代码行数:88,代码来源:XercesSaxParseBase.cpp

示例4: main


//.........这里部分代码省略.........
        }
         else if (!strcmp(argV[parmInd], "-p")
              ||  !strcmp(argV[parmInd], "-P"))
        {
            namespacePrefixes = true;
        }
         else if (!strcmp(argV[parmInd], "-sa"))
        {
            sortAttributes = true;
        }
         else
        {
            XERCES_STD_QUALIFIER cerr << "Unknown option '" << argV[parmInd]
                 << "', ignoring it\n" << XERCES_STD_QUALIFIER endl;
        }
    }

    //
    //  And now we have to have only one parameter left and it must be
    //  the file name.
    //
    if (parmInd + 1 != argC)
    {
        usage();
        XMLPlatformUtils::Terminate();
        return 1;
    }
    xmlFile = argV[parmInd];

    //
    //  Create a SAX parser object. Then, according to what we were told on
    //  the command line, set it to validate or not.
    //
    SAX2XMLReader* parser;
    SAX2XMLReader* reader = XMLReaderFactory::createXMLReader();
    SAX2XMLReader* filter = NULL;
    if(sortAttributes)
    {
        filter=new SAX2SortAttributesFilter(reader);
        parser=filter;
    }
    else
        parser=reader;

    //
    //  Then, according to what we were told on
    //  the command line, set it to validate or not.
    //
    if (valScheme == SAX2XMLReader::Val_Auto)
    {
        parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
        parser->setFeature(XMLUni::fgXercesDynamic, true);
    }

    if (valScheme == SAX2XMLReader::Val_Never)
    {
        parser->setFeature(XMLUni::fgSAX2CoreValidation, false);
    }

    if (valScheme == SAX2XMLReader::Val_Always)
    {
        parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
        parser->setFeature(XMLUni::fgXercesDynamic, false);
    }

    parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, doNamespaces);
开发者ID:gitrider,项目名称:wxsj2,代码行数:67,代码来源:SAX2Print.cpp

示例5: main


//.........这里部分代码省略.........
        {
            namespacePrefixes = true;
        }
         else if (!strcmp(argV[argInd], "-special:nel"))
        {
            // turning this on will lead to non-standard compliance behaviour
            // it will recognize the unicode character 0x85 as new line character
            // instead of regular character as specified in XML 1.0
            // do not turn this on unless really necessary
            XMLPlatformUtils::recognizeNEL(true);
        }
        else
        {
            cerr << "Unknown option '" << argV[argInd]
                << "', ignoring it\n" << endl;
        }
    }

    //
    //  There should be only one and only one parameter left, and that
    //  should be the file name.
    //
    if (argInd != argC - 1)
    {
        usage2();
        cms::concurrency::xercesTerminate();
        return 1;
    }

    //
    //  Create a SAX parser object. Then, according to what we were told on
    //  the command line, set it to validate or not.
    //
    SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
    parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, doNamespaces);
    parser->setFeature(XMLUni::fgXercesSchema, doSchema);
    parser->setFeature(XMLUni::fgXercesSchemaFullChecking, schemaFullChecking);
    parser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, namespacePrefixes);

    if (valScheme == SAX2XMLReader::Val_Auto)
    {
        parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
        parser->setFeature(XMLUni::fgXercesDynamic, true);
    }
    if (valScheme == SAX2XMLReader::Val_Never)
    {
        parser->setFeature(XMLUni::fgSAX2CoreValidation, false);
    }
    if (valScheme == SAX2XMLReader::Val_Always)
    {
        parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
        parser->setFeature(XMLUni::fgXercesDynamic, false);
    }

    //
    //  Create our SAX handler object and install it on the parser, as the
    //  document and error handler.
    //
    SaxToDom2 handler;
    parser->setContentHandler(&handler);
    parser->setErrorHandler(&handler);

    //
    //  Get the starting time and kick off the parse of the indicated
    //  file. Catch any exceptions that might propogate out of it.
    //
开发者ID:JanFSchulte,项目名称:cmssw,代码行数:67,代码来源:simple_dom_parser2.cpp

示例6: parseXML

void parseXML(xercesc::InputSource* src,SAX2ContentHandler* handler)
{
	SAX2XMLReader::ValSchemes    valScheme    = SAX2XMLReader::Val_Always;
	bool                         doNamespaces = true;
	bool                         doSchema = true;
	bool                         schemaFullChecking = false;
	bool                         identityConstraintChecking = true;
	bool                         errorOccurred = false;
	bool                         namespacePrefixes = false;
	//bool                         recognizeNEL = false;
	char                         localeStr[64];
	memset(localeStr, 0, sizeof localeStr);

	//
	//  Create a SAX parser object. Then, according to what we were told on
	//  the command line, set it to validate or not.
	//
	SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
	parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, doNamespaces);
	parser->setFeature(XMLUni::fgXercesSchema, doSchema);
	parser->setFeature(XMLUni::fgXercesHandleMultipleImports, true);
	parser->setFeature(XMLUni::fgXercesSchemaFullChecking, schemaFullChecking);
	parser->setFeature(XMLUni::fgXercesIdentityConstraintChecking, identityConstraintChecking);
	parser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, namespacePrefixes);

	if (valScheme == SAX2XMLReader::Val_Auto)
	{
		parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
		parser->setFeature(XMLUni::fgXercesDynamic, true);
	}
	if (valScheme == SAX2XMLReader::Val_Never)
	{
		parser->setFeature(XMLUni::fgSAX2CoreValidation, false);
	}
	if (valScheme == SAX2XMLReader::Val_Always)
	{
		parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
		parser->setFeature(XMLUni::fgXercesDynamic, false);
	}

	parser->setContentHandler(handler);
	//parser->setErrorHandler(handler);

	XMLPScanToken token;

	try
	{
		parser->parse(*src);
	}
	catch (const OutOfMemoryException&)
	{
		std::cerr << "OutOfMemoryException" << std::endl;
		errorOccurred = true;
	}
	catch (const XMLException& e)
	{
		std::cerr << "\nError during parsing; Exception message is:  \n"
				<< e.getMessage() << "\n" << std::endl;
		errorOccurred = true;
	}
	catch (const std::exception& e)
	{
		std::cerr << std::endl << "std::exception caught during parsing of bz2 stream: what='" << e.what() << "'" << std::endl;
		errorOccurred = true;
	}
	catch (...)
	{
		std::cerr << "\nUnexpected exception during parsing of bz2 stream\n";
		errorOccurred = true;
	}

	if(errorOccurred)
		cerr << "Error in parsing" << endl;
}
开发者ID:darongE,项目名称:osm2bin,代码行数:74,代码来源:ParseXML.cpp

示例7: main

// ---------------------------------------------------------------------------
//  Program entry point
// ---------------------------------------------------------------------------
int main(int argC, char* argV[])
{
    // Initialize the XML4C system
    try
    {
         XMLPlatformUtils::Initialize();
    }

    catch (const XMLException& toCatch)
    {
         XERCES_STD_QUALIFIER cerr << "Error during initialization! Message:\n"
              << StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
         return 1;
    }


    SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();

    srcml2tokenHandlers handler;
    parser->setContentHandler(&handler);
    parser->setErrorHandler(&handler);

    int errorCount = 0;
    // create a faux scope so that 'src' destructor is called before
    // XMLPlatformUtils::Terminate
    {
        //
        //  Kick off the parse and catch any exceptions. Create a standard
        //  input input source and tell the parser to parse from that.
        //
        try
        {
            if (argC < 2) {
                StdInInputSource src;
                parser->parse(src);
            } else {
                parser->parse(argV[1]);
            }
        }
        catch (const OutOfMemoryException&)
        {
            XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
            errorCount = 2;
            return 4;
        }
        catch (const XMLException& e)
        {
            XERCES_STD_QUALIFIER cerr << "\nError during parsing: \n"
                 << StrX(e.getMessage())
                 << "\n" << XERCES_STD_QUALIFIER endl;
            errorCount = 1;
            return 4;
        }

    }

    //
    //  Delete the parser itself.  Must be done prior to calling Terminate, below.
    //
    delete parser;

    XMLPlatformUtils::Terminate();

    if (errorCount > 0)
        return 4;
    else
        return 0;
}
开发者ID:dmgerman,项目名称:cregit,代码行数:71,代码来源:srcml2token.cpp


注:本文中的SAX2XMLReader::parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。