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


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

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


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

示例1: isValid

  bool XMLValidator::isValid(const String & filename, const String & schema, std::ostream & os)
  {
    filename_ = filename;
    os_ = &os;

    //try to open file
    if (!File::exists(filename))
    {
      throw Exception::FileNotFound(__FILE__, __LINE__, __PRETTY_FUNCTION__, filename);
    }

    // initialize parser
    try
    {
      XMLPlatformUtils::Initialize();
    }
    catch (const XMLException & toCatch)
    {
      throw Exception::ParseError(__FILE__, __LINE__, __PRETTY_FUNCTION__, "", String("Error during initialization: ") + Internal::StringManager().convert(toCatch.getMessage()));
    }

    SAX2XMLReader * parser = XMLReaderFactory::createXMLReader();
    parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
    parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
    parser->setFeature(XMLUni::fgXercesDynamic, false);
    parser->setFeature(XMLUni::fgXercesSchema, true);
    parser->setFeature(XMLUni::fgXercesSchemaFullChecking, true);

    //set this class as error handler
    parser->setErrorHandler(this);
    parser->setContentHandler(NULL);
    parser->setEntityResolver(NULL);

    //load schema
    LocalFileInputSource schema_file(Internal::StringManager().convert(schema));
    parser->loadGrammar(schema_file, Grammar::SchemaGrammarType, true);
    parser->setFeature(XMLUni::fgXercesUseCachedGrammarInParse, true);

    // try to parse file
    LocalFileInputSource source(Internal::StringManager().convert(filename.c_str()));

    try
    {
      parser->parse(source);
      delete(parser);
    }
    catch (...)
    {
      /// nothing to do here
    }

    return valid_;
  }
开发者ID:chahuistle,项目名称:OpenMS,代码行数:53,代码来源:XMLValidator.cpp

示例2: loadall_xml

// Other include files, declarations, and non-Xerces-C++ initializations.
XERCES_CPP_NAMESPACE_USE 
  
/*int main(int argc, char** argv){
	char* xmlFile = "well-formatted-new.xml";
	//char *xmlFile = "GridLABD_Multi_Example.xml";
	return loadall_xml(xmlFile);
}*/

int loadall_xml(char *filename){
	if(filename == NULL)
		return 0;
	try{
		XMLPlatformUtils::Initialize();
	} catch(const XMLException& /*toCatch*/){
		output_error("Load_XML: Xerces Initialization failed.");
		output_debug(" * something really spectacularly nasty happened inside Xerces and outside our control.");
		return 0;
	}

	SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
	parser->setFeature(XMLUni::fgXercesDynamic, true);
	//parser->setFeature(XMLUni::fgSAX2CoreValidation, true);   
	//parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);   // optional

	gld_loadHndl *defaultHandler = new gld_loadHndl();
	parser->setContentHandler(defaultHandler);
	parser->setErrorHandler(defaultHandler);
	
	try {
		parser->parse(filename);
	} catch (const XMLException& toCatch){
		char* message = XMLString::transcode(toCatch.getMessage());
		output_error("Load_XML: XMLException from Xerces: %s", message);
		XMLString::release(&message);
		return 0;
	} catch (const SAXParseException& toCatch){
		char* message = XMLString::transcode(toCatch.getMessage());
		output_error("Load_XML: SAXParseException from Xerces: %s", message);
		XMLString::release(&message);
		return 0;
	} catch (...) {
		output_error("Load_XML: unexpected exception from Xerces.");
		return 0;
	}
	if(!defaultHandler->did_load()){
		output_error("Load_XML: loading failed.");
		return 0;
	}
	delete parser;
	delete defaultHandler;
	return 1;
}
开发者ID:devendrashelar7,项目名称:gridnetd,代码行数:53,代码来源:load_xml.cpp

示例3: handler

bool
O2Profile::
ImportFromXML(const wchar_t *filename, const char *in, uint len)
{
	bool ret = false;

	SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
	O2Profile_SAX2Handler handler(Logger, this);
	parser->setContentHandler(&handler);
	parser->setErrorHandler(&handler);

	Lock();
	{
		try {
			if (filename) {
#ifdef _MSC_VER			/** VC++ */
				LocalFileInputSource source(filename);
#else				/** GCC/Clang */
				LocalFileInputSource source(reinterpret_cast<const XMLCh*>(filename));
#endif
				parser->parse(source);
			}
			else {
				MemBufInputSource source((const XMLByte*)in, len, "");
				parser->parse(source);
			}
			ret = true;
		}
		catch (const OutOfMemoryException &e) {
			if (Logger) {
				Logger->AddLog(O2LT_ERROR, MODULE, 0, 0,
					L"SAX2: Out of Memory: %s", e.getMessage());
			}
		}
		catch (const XMLException &e) {
			if (Logger) {
				Logger->AddLog(O2LT_ERROR, MODULE, 0, 0,
					L"SAX2: Exception: %s", e.getMessage());
			}
		}
		catch (...) {
			if (Logger) {
				Logger->AddLog(O2LT_ERROR, MODULE, 0, 0,
					L"SAX2: Unexpected exception during parsing.");
			}
		}
	}
	Unlock();

	delete parser;
	return (ret);
}
开发者ID:Hiroyuki-Nagata,项目名称:o2on,代码行数:52,代码来源:O2Profile.cpp

示例4: ReadFile

    int GpXmlReader::ReadFile(string& filename, GpCodeModel* model)
    {
        DEBOUT("GpXmlReader::ReadFile()");
        SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
        parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
        parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true); // optional

        if (!model)
        {
            throw std::invalid_argument("Null pointer passed to  GpXmlReader::ReadFile()");
        }

        GpXmlSAXContentHandler* handler = new GpXmlSAXContentHandler(model);
        parser->setContentHandler(handler);
        parser->setErrorHandler(handler);

        try
        {
            parser->parse(filename.c_str() );
        }
        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 (const std::exception& except)
        {
            cout << except.what() << '\n';
            return -1;
        }
        catch (...)
        {
            cout << "Unexpected Exception \n";
            return -1;
        }

        delete parser;
        delete handler;
        return 0;
    }
开发者ID:thepresence,项目名称:gpos,代码行数:51,代码来源:GpXmlReader.cpp

示例5: SHandler

/*
 =======================================================================================================================
 *  TODO:
 =======================================================================================================================
 */
void cLoadXML::Sax2ReadXML (const char* filename) {

	/* create SAX2 parser and read the basic building block setting file */
	SAX2XMLReader*	parser;

	/* create handler that will parse the XML elements */
	SHandler*  handler;
	parser = XMLReaderFactory::createXMLReader ();
	handler = new SHandler (recordNode, recordLink, nodeIndex, linkIndex);

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

	try
	{
		parser->parse (filename);
	}

	catch (const XMLException&toCatch) {
		char*  message;
		message = XMLString::transcode (toCatch.getMessage ());

		/*
		 * err << "Exception message is: \n" ;
		 * << message << "\n";
		 */
		XMLString::release (&message);
	}

	catch (const SAXParseException&toCatch) {
		char*  message;
		message = XMLString::transcode (toCatch.getMessage ());

		/*
		 * err << "Exception message is: \n" ;
		 * << message << "\n";
		 */
		XMLString::release (&message);
	}

	catch (...) {

		/*
		 * err << "Unexpected Exception \n" ;
		 */
	}

	delete parser;
	delete handler;
	XMLPlatformUtils::Terminate ();
}
开发者ID:llewelld,项目名称:MATTS,代码行数:56,代码来源:cLoadXML.cpp

示例6: getParser

static SAX2XMLReader* getParser(XMLGrammarPool* const theGramPool
                              , bool                  setHandler)
{
    SAX2XMLReader* parser = XMLReaderFactory::createXMLReader(theGramPool->getMemoryManager(), theGramPool);

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

    if (setHandler)
    {
        parser->setContentHandler(handler);
        parser->setErrorHandler(handler);
    }
    else
    {
        parser->setContentHandler(0);
        parser->setErrorHandler(0);
    }

    return parser;
}
开发者ID:gitrider,项目名称:wxsj2,代码行数:38,代码来源:XSerializerTest.cpp

示例7: parseURL

//////////////////////////////////////////////////////////////////////////////
/// \brief 지정된 위치에 있는 파일 또는 웹 문서를 파싱한다.
/// 
/// \param pURL 
//////////////////////////////////////////////////////////////////////////////
void XMLParser::parseURL(const char* pURL)
{
	assert(pURL != NULL);
	assert(m_pHandler != NULL);

	// SAX 파서 오브젝트를 생성한다. 그리고 feature를 설정한다.
	// SAX2에서 지원되는 feature는 다음과 같다.
	//
	// validation (default: true) 
	// namespaces (default: true) 
	// namespace-prefixes (default: false) 
	// validation/dynamic (default: false) 
	// reuse-grammar (default: false) 
	// schema (default: true) 
	// schema-full-checking (default: false) 
	// load-external-dtd (default: true) 
	// continue-after-fatal-error (default: false) 
	// validation-error-as-fatal (default: false) 
	//
	// 자세한 사항은 다음 주소를 참고하기 바란다.
	// http://xml.apache.org/xerces-c/program-sax2.html#SAX2Features 
	SAX2XMLReader* pParser = XMLReaderFactory::createXMLReader();
	pParser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
	pParser->setFeature(XMLUni::fgXercesSchema, true);
	pParser->setFeature(XMLUni::fgXercesSchemaFullChecking, false);
	pParser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, false);
	pParser->setFeature(XMLUni::fgSAX2CoreValidation, true);
	pParser->setFeature(XMLUni::fgXercesDynamic, true);
	pParser->setContentHandler(m_pHandler);
	pParser->setErrorHandler(m_pHandler);

	try
	{
		pParser->parse(pURL);
	}
	catch (const XMLException& e)
	{
		XMLUtil::filelog(
			"\nError during parsing! Exception Message: \n%s\n",
			XMLUtil::WideCharToString(e.getMessage()).c_str());
	}
	catch (...)
	{
		XMLUtil::filelog(
			"Unexpected exception during parsing!\n");
	}

	delete pParser;
}
开发者ID:hillwah,项目名称:darkeden,代码行数:54,代码来源:SXml.cpp

示例8: main

int main (int argc, char* args[]) {

	try {
		XMLPlatformUtils::Initialize();
	}
	catch (const XMLException& toCatch) {
		char* message = XMLString::transcode(toCatch.getMessage());
		cout << "Error during initialization! :\n";
		cout << "Exception message is: \n"
			<< message << "\n";
		XMLString::release(&message);
		return 1;
	}

	StdInInputSource lStdInStream;
	SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
	parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
	parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);   // optional

	XMLSerializer* defaultHandler = new XMLSerializer(wcout);
	parser->setContentHandler(defaultHandler);
	parser->setErrorHandler(defaultHandler);

	try {
		parser->parse(lStdInStream);
	}
	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 defaultHandler;
	return 0;
}
开发者ID:PeterWang9,项目名称:code,代码行数:49,代码来源:stdin_parser.cpp

示例9:

    XERCES_CPP_NAMESPACE::SAX2XMLReader* XercesParser::createReader(XERCES_CPP_NAMESPACE::DefaultHandler& handler)
    {
        XERCES_CPP_NAMESPACE_USE;

        SAX2XMLReader* reader = XMLReaderFactory::createXMLReader();

        // set basic settings we want from parser
        reader->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);

        // set handlers
        reader->setContentHandler(&handler);
        reader->setErrorHandler(&handler);

        return reader;
    }
开发者ID:Silentfood,项目名称:oonline,代码行数:15,代码来源:CEGUIXercesParser.cpp

示例10: source

// ---------------------------------------------------------------------------
//	LoadEx()
//	独自の情報を別ファイルから読む
// ---------------------------------------------------------------------------
bool
O2Boards::
LoadEx(void)
{
	bool ret = false;

	struct _stat st;
	if (_wstat(exfilepath.c_str(), &st) == -1)
		return false;
	if (st.st_size == 0)
		return false;

	SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
	parser->setContentHandler(this);
	parser->setErrorHandler(this);

	try {
#ifdef _MSC_VER
		LocalFileInputSource source(exfilepath.c_str());
#else
		LocalFileInputSource source(reinterpret_cast<const XMLCh*>(exfilepath.c_str()));
#endif
		parser->parse(source);
		ret = true;
	}
	catch (const OutOfMemoryException &e) {
		if (Logger) {
			Logger->AddLog(O2LT_ERROR, MODULE, 0, 0,
				L"SAX2: Out of Memory: %s", e.getMessage());
		}
	}
	catch (const XMLException &e) {
		if (Logger) {
			Logger->AddLog(O2LT_ERROR, MODULE, 0, 0,
				L"SAX2: Exception: %s", e.getMessage());
		}
	}
	catch (...) {
		if (Logger) {
			Logger->AddLog(O2LT_ERROR, MODULE, 0, 0,
				L"SAX2: Unexpected exception during parsing.");
		}
	}

	delete parser;
	return (ret);
}
开发者ID:Hiroyuki-Nagata,项目名称:o2on,代码行数:51,代码来源:O2Boards.cpp

示例11: handler

size_t
O2IMDB::
ImportFromXML(const wchar_t *filename, const char *in, uint len)
{
	SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
	O2IMDB_SAX2Handler handler(Logger, this);
	parser->setContentHandler(&handler);
	parser->setErrorHandler(&handler);

	try {
		if (filename) {

#ifdef _MSC_VER         /** loose VC++ cast...*/
			LocalFileInputSource source(filename);
#else                   /** use reinterpret_cast for GCC */
			LocalFileInputSource source(reinterpret_cast<const XMLCh*>(filename));
#endif
			parser->parse(source);
		}
		else {
			MemBufInputSource source((const XMLByte*)in, len, "");
			parser->parse(source);
		}
	}
	catch (const OutOfMemoryException &e) {
		if (Logger) {
			Logger->AddLog(O2LT_ERROR, MODULE, 0, 0,
				L"SAX2: Out of Memory: %s", e.getMessage());
		}
	}
	catch (const XMLException &e) {
		if (Logger) {
			Logger->AddLog(O2LT_ERROR, MODULE, 0, 0,
				L"SAX2: Exception: %s", e.getMessage());
		}
	}
	catch (...) {
		if (Logger) {
			Logger->AddLog(O2LT_ERROR, MODULE, 0, 0,
				L"SAX2: Unexpected exception during parsing.");
		}
	}

	delete parser;
	return (handler.GetParseNum());
}
开发者ID:Hiroyuki-Nagata,项目名称:o2on,代码行数:46,代码来源:O2IMDB.cpp

示例12: handler

//____________________________________________________________________________
void X2DB::parse(request_rec *r, my_server_config *config, const char *buf,
				 apr_size_t len)
{
	try {
		XMLPlatformUtils::Initialize();
	} catch (const XMLException &x) {
		XERCES_STD_QUALIFIER cout << "Error during initialization! :\n"
			<< XMLString::transcode(x.getMessage()) << XERCES_STD_QUALIFIER endl;
		return;
	}
    SAX2XMLReader *parser = XMLReaderFactory::createXMLReader();
	parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
	parser->setFeature(XMLUni::fgXercesDynamic, true);
    parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
    parser->setFeature(XMLUni::fgXercesSchema, true);
    parser->setFeature(XMLUni::fgXercesSchemaFullChecking, false);
    parser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, false);
    int errorCode = 0;
	try {
		X2DB handler(r, config);
		parser->setContentHandler(&handler);
		parser->setErrorHandler(&handler);
		ap_rputs("<result>", r);
		parser->parse(MemBufInputSource(reinterpret_cast<XMLByte *>(const_cast<char *>(buf)), len, "HTTP"));
		ap_rprintf(r, "<parse-errors count=\"%d\"/>", parser->getErrorCount());
		ap_rputs("</result>", r);
	} catch (const OutOfMemoryException &) {
		XERCES_STD_QUALIFIER cout << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
		errorCode = 5;
	} catch (const XMLException &x) {
		XERCES_STD_QUALIFIER cout << "\nAn error occurred\n  Error: "
			<< XMLString::transcode(x.getMessage())
			<< "\n" << XERCES_STD_QUALIFIER endl;
		errorCode = 4;
	}
	if (errorCode) {
		XMLPlatformUtils::Terminate();
		return;
	}
	delete parser;
	XMLPlatformUtils::Terminate();
	return;
}
开发者ID:bshapcott,项目名称:modmite,代码行数:44,代码来源:x2db.xerces.cpp

示例13: handler

uint64
O2IPFilter::
ImportFromXML(const wchar_t *filename, const char *in, uint len)
{
	SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
	O2IPFilter_SAX2Handler handler(name.c_str(), Logger, this);
	parser->setContentHandler(&handler);
	parser->setErrorHandler(&handler);

	try {
		if (filename) {
			LocalFileInputSource source(filename);
			parser->parse(source);
		}
		else {
			MemBufInputSource source((const XMLByte*)in, len, "");
			parser->parse(source);
		}
	}
	catch (const OutOfMemoryException &e) {
		if (Logger) {
			Logger->AddLog(O2LT_ERROR, name.c_str(), 0, 0,
				L"SAX2: Out of Memory: %s", e.getMessage());
		}
	}
	catch (const XMLException &e) {
		if (Logger) {
			Logger->AddLog(O2LT_ERROR, name.c_str(), 0, 0,
				L"SAX2: Exception: %s", e.getMessage());
		}
	}
	catch (...) {
		if (Logger) {
			Logger->AddLog(O2LT_ERROR, name.c_str(), 0, 0,
				L"SAX2: Unexpected exception during parsing.");
		}
	}

	delete parser;
	return (handler.GetParseNum());
}
开发者ID:idobatter,项目名称:o2on,代码行数:41,代码来源:O2IPFilter.cpp

示例14: parse

//////////////////////////////////////////////////////////////////////////////
/// \brief 인수로 넘겨지는 문자열을 XML 문서로 가정하고 파싱한다.
/// 
/// \param buffer 
//////////////////////////////////////////////////////////////////////////////
void XMLParser::parse(const char* buffer)
{
	assert(buffer != NULL);
	assert(m_pHandler != NULL);

	// SAX 파서 오브젝트를 생성한다. 그리고 feature를 설정한다.
	// feature에 관한 사항은 XMLParser::parseURL() 함수를 참고하기 바란다.
	SAX2XMLReader* pParser = XMLReaderFactory::createXMLReader();
	pParser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
	pParser->setFeature(XMLUni::fgXercesSchema, true);
	pParser->setFeature(XMLUni::fgXercesSchemaFullChecking, false);
	pParser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, false);
	pParser->setFeature(XMLUni::fgSAX2CoreValidation, true);
	pParser->setFeature(XMLUni::fgXercesDynamic, true);
	pParser->setContentHandler(m_pHandler);
	pParser->setErrorHandler(m_pHandler);

	try
	{
		MemBufInputSource source(
			(const XMLByte*)(buffer), (unsigned int)strlen(buffer), "", false);
		pParser->parse(source);
	}
	catch (const XMLException& e)
	{
		XMLUtil::filelog(
			"\nError during parsing! Exception Message: \n%s\n",
			XMLUtil::WideCharToString(e.getMessage()).c_str());
	}
	catch (...)
	{
		XMLUtil::filelog(
			"Unexpected exception during parsing!\n");
	}

	delete pParser;
}
开发者ID:hillwah,项目名称:darkeden,代码行数:42,代码来源:SXml.cpp

示例15: main


//.........这里部分代码省略.........
    //  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);
    parser->setFeature(XMLUni::fgXercesSchema, doSchema);
    parser->setFeature(XMLUni::fgXercesSchemaFullChecking, schemaFullChecking);
    parser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, namespacePrefixes);

    //
    //  Create the handler object and install it as the document and error
    //  handler for the parser. Then parse the file and catch any exceptions
    //  that propogate out
    //

    int errorCount = 0;
    int errorCode = 0;
    try
    {
        SAX2PrintHandlers handler(encodingName, unRepFlags, expandNamespaces);
        parser->setContentHandler(&handler);
        parser->setErrorHandler(&handler);
        parser->parse(xmlFile);
        errorCount = parser->getErrorCount();
    }
    catch (const OutOfMemoryException&)
    {
        XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
        errorCode = 5;          
    }
    catch (const XMLException& toCatch)
    {
        XERCES_STD_QUALIFIER cerr << "\nAn error occurred\n  Error: "
             << StrX(toCatch.getMessage())
             << "\n" << XERCES_STD_QUALIFIER endl;
        errorCode = 4;
    }

    if(errorCode) {
        XMLPlatformUtils::Terminate();
        return errorCode;
    }

    //
    //  Delete the parser itself.  Must be done prior to calling Terminate, below.
    //
    delete reader;
    if(filter)
        delete filter;

    // And call the termination method
    XMLPlatformUtils::Terminate();

    if (errorCount > 0)
        return 4;
    else
        return 0;
}
开发者ID:xin3liang,项目名称:platform_external_xerces-cpp,代码行数:101,代码来源:SAX2Print.cpp


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