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


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

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


在下文中一共展示了SAX2XMLReader::setFeature方法的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: TestInit4SAX2

// ---------------------------------------------------------------------------
//  SAX2 XML Reader
// ---------------------------------------------------------------------------
int TestInit4SAX2(const char* xmlFile, bool gDoNamespaces, bool gDoSchema, bool gSchemaFullChecking, Teststate theState)
{
    TESTINITPRE;
    SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();

    XMLCh* doNamespaceFeature = XMLString::transcode("http://xml.org/sax/features/namespaces");
    parser->setFeature(doNamespaceFeature, gDoNamespaces);

    XMLCh* doSchemaFeature = XMLString::transcode("http://apache.org/xml/features/validation/schema");
    parser->setFeature(doSchemaFeature, gDoSchema);

    XMLCh* fullSchemaCheckFeature = XMLString::transcode("http://apache.org/xml/features/validation/schema-full-checking");
    parser->setFeature(fullSchemaCheckFeature, gSchemaFullChecking);

    XMLString::release(&doNamespaceFeature);
    XMLString::release(&doSchemaFeature);
    XMLString::release(&fullSchemaCheckFeature);

    TESTINITPOST;
}
开发者ID:gitrider,项目名称:wxsj2,代码行数:23,代码来源:InitTermTest.cpp

示例3: 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

示例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: parseOne

static 
bool parseOne(BinOutputStream*    outStream
            , const char* const   xmlFile)
{
    //we don't use janitor here
    MemoryManager*  theMemMgr   = new MemoryManagerImpl();
    XMLGrammarPool* theGramPool = new XMLGrammarPoolImpl(theMemMgr);
    SAX2XMLReader*  theParser   = getParser(theGramPool, false);  //don't emit error
    bool            retVal      = true;

    theParser->setFeature(XMLUni::fgXercesCacheGrammarFromParse, true);

    //scan instance document and cache grammar
    try
    {
        theParser->parse(xmlFile);
    }
    catch (...)
    {
        //do nothing, it could be an invalid instance document, but the grammar is fine
    }

    //serialize the grammar pool
    try
    {
        theGramPool->serializeGrammars(outStream);
    }
    catch (const XSerializationException& e)
    {
        //do emit error here so that we know serialization failure
        XERCES_STD_QUALIFIER cerr << "An error occurred during serialization\n   Message: "
            << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;

        retVal = false;
    }

    catch (...)
    {
        //do emit error here so that we know serialization failure
        XERCES_STD_QUALIFIER cerr << "An error occurred during serialization\n" << XERCES_STD_QUALIFIER endl;

        retVal = false;
    }

    //the order is important
    delete theParser;
    delete theGramPool;
    delete theMemMgr;

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

示例6: 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

示例7:

    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

示例8: parseTwo

static 
void parseTwo(BinInputStream*     inStream
            , const char* const   xmlFile)
{
    //we don't use janitor here
    MemoryManager*  theMemMgr   = new MemoryManagerImpl();
    XMLGrammarPool* theGramPool = new XMLGrammarPoolImpl(theMemMgr);
    bool            errorSeen   = false;

    //de-serialize grammar pool
    try
    {
        theGramPool->deserializeGrammars(inStream);
    }

    catch(const XSerializationException& e)
    {
        XERCES_STD_QUALIFIER cerr << "An error occurred during de-serialization\n   Message: "
            << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;

        errorSeen = true;
    }

    catch (...)
    {
        //do emit error here so that we know serialization failure
        XERCES_STD_QUALIFIER cerr << "An error occurred during de-serialization\n" << XERCES_STD_QUALIFIER endl;

        errorSeen = true;
    }

    if (!errorSeen)
    {
        SAX2XMLReader*  theParser   = getParser(theGramPool, true); //set the handler

        theParser->setFeature(XMLUni::fgXercesUseCachedGrammarInParse, true);
        parseFile(theParser, xmlFile);
        delete theParser;
    }

    //the order is important
    delete theGramPool;
    delete theMemMgr;

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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: main


//.........这里部分代码省略.........
    //
    //  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);
    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);
开发者ID:xin3liang,项目名称:platform_external_xerces-cpp,代码行数:67,代码来源:SAX2Print.cpp

示例14: main

int main(int argc, char** argv)
{
  const char* encodingName = "UTF-8";
  //SAX2XMLReader::ValSchemes valScheme = SAX2XMLReader::Val_Auto;
  SAX2XMLReader::ValSchemes valScheme = SAX2XMLReader::Val_Always;
  bool expandNamespaces = false;
  bool doNamespaces = true;
  bool doSchema = true;
  bool schemaFullChecking = true;
  bool namespacePrefixes = false;
  SAX2XMLReader* parser = 0;
  
  try
  {
    XMLPlatformUtils::Initialize();
  }

  catch (const XMLException& toCatch)
  {
    cout << " Error during XML initialization :\n"
         << StrX(toCatch.getMessage()) << endl;
  }
    
  parser = XMLReaderFactory::createXMLReader();
  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);

  int errorCount = 0;
  XMLPScanToken token;
 
  try
  {
    TestHandler handler;
    parser->setContentHandler(&handler);
    parser->setErrorHandler(&handler);

    if ( !parser->parseFirst(argv[1],token) )
    {
      cout << "parseFirst() failed" << endl;
      XMLPlatformUtils::Terminate();
      exit(1);
    }
    cout << "parseFirst() completed" << endl;

    bool gotMore = true;
    bool done = false;
    while ( gotMore && !done )
    {
      gotMore = parser->parseNext(token);
      if ( !gotMore )
        cout << "parseNext() returned 0" << endl;
      cout << "buffer = " << handler.buffer << endl;
      if ( handler.buffer.size() > 32 )
        handler.buffer = "";
    }

    errorCount = parser->getErrorCount();
    
    cout << handler.buffer << endl;
  }

  catch (const XMLException& toCatch)
  {
    cout << "\nAn error occurred\n  Error: "
         << StrX(toCatch.getMessage())
         << "\n" << endl;
    XMLPlatformUtils::Terminate();
    delete parser;
    throw;
  }

  catch (const SAXParseException& e)
  {
    cout << "\na SAXParseException occurred in file "
         << StrX(e.getSystemId())
         << ", line " << e.getLineNumber()
         << ", char " << e.getColumnNumber()
         << "\n  Message: " << StrX(e.getMessage()) << endl;
    XMLPlatformUtils::Terminate();
    delete parser;
    throw;
//.........这里部分代码省略.........
开发者ID:xorJane,项目名称:qball,代码行数:101,代码来源:testPParse.C

示例15: main

// ---------------------------------------------------------------------------
//  Program entry point
// ---------------------------------------------------------------------------
int main(int argC, char* argV[])
{
    // Check command line and extract arguments.
    if (argC < 2)
    {
        usage();
        return 1;
    }

    // cannot return out of catch-blocks lest exception-destruction
    // result in calls to destroyed memory handler!
    int errorCode = 0;
    try
    {
        XMLPlatformUtils::Initialize();
    }
    
    catch (const XMLException& toCatch)
    {
        XERCES_STD_QUALIFIER cerr   << "Error during initialization! Message:\n"
        << StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
        errorCode = 2;
    }
    if(errorCode) {
        XMLPlatformUtils::Terminate();
        return errorCode;
    }

    bool							doList				= false;
    bool							schemaFullChecking	= false;
    const char*                     xsdFile             = 0;
    int argInd;

    for (argInd = 1; argInd < argC; argInd++)
    {
        // Break out on first parm not starting with a dash
        if (argV[argInd][0] != '-')
            break;

        // Watch for special case help request
        if (!strcmp(argV[argInd], "-?"))
        {
            usage();
            return 1;
        }
        else if (!strcmp(argV[argInd], "-l")
              ||  !strcmp(argV[argInd], "-L"))
        {
            doList = true;
        }
        else if (!strcmp(argV[argInd], "-f")
              ||  !strcmp(argV[argInd], "-F"))
        {
            schemaFullChecking = true;
        }
        else
        {
            XERCES_STD_QUALIFIER cerr << "Unknown option '" << argV[argInd]
                << "', ignoring it\n" << XERCES_STD_QUALIFIER endl;
        }
    }

    //
    //  There should be only one and only one parameter left, and that
    //  should be the file name.
    //
    if (argInd != argC - 1)
    {
        usage();
        return 1;
    }
    
    XMLGrammarPool *grammarPool;
    SAX2XMLReader* parser;
    try
    {        
        grammarPool = new XMLGrammarPoolImpl(XMLPlatformUtils::fgMemoryManager);

        parser = XMLReaderFactory::createXMLReader(XMLPlatformUtils::fgMemoryManager, grammarPool);
        parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
        parser->setFeature(XMLUni::fgXercesSchema, true);
        parser->setFeature(XMLUni::fgXercesSchemaFullChecking, schemaFullChecking);
        parser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, false);
        parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
        parser->setFeature(XMLUni::fgXercesDynamic, true);
        parser->setProperty(XMLUni::fgXercesScannerName, (void *)XMLUni::fgSGXMLScanner);

        SCMPrintHandler handler;    
        parser->setErrorHandler(&handler);

        bool more = true;
        bool parsedOneSchemaOkay = false;
        XERCES_STD_QUALIFIER ifstream fin;

        // the input is a list file
        if (doList)
            fin.open(argV[argInd]);
//.........这里部分代码省略.........
开发者ID:QEver,项目名称:vosproj,代码行数:101,代码来源:SCMPrint.cpp


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