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


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

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


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


//.........这里部分代码省略.........
        // the input is a list file
        if (doList)
            fin.open(argV[argInd]);

        if (fin.fail()) {
            XERCES_STD_QUALIFIER cerr <<"Cannot open the list file: " << argV[argInd] << XERCES_STD_QUALIFIER endl;
            return 3;
        }

        while (more)
        {            
            char fURI[1000];
            //initialize the array to zeros
            memset(fURI,0,sizeof(fURI));

            if (doList) {
                if (! fin.eof() ) {
                    fin.getline (fURI, sizeof(fURI));
                    if (!*fURI)
                        continue;
                    else {
                        xsdFile = fURI;
                        XERCES_STD_QUALIFIER cerr << "==Parsing== " << xsdFile << XERCES_STD_QUALIFIER endl;
                    }
                }
                else
                    break;
            }
            else {
                xsdFile = argV[argInd];
                more = false;
            }

            parser->loadGrammar(xsdFile, Grammar::SchemaGrammarType, true);
            if (handler.getSawErrors())
            {
                handler.resetErrors();
            }
            else
            {
                parsedOneSchemaOkay = true;
            }
        }

        if (parsedOneSchemaOkay)
        {
            XERCES_STD_QUALIFIER cout << "********** Printing out information from Schema **********" << "\n\n";
            bool updatedXSModel;
            XSModel *xsModel = grammarPool->getXSModel(updatedXSModel);
            if (xsModel)
            {    
                StringList *namespaces = xsModel->getNamespaces();
                for (unsigned i = 0; i < namespaces->size(); i++) {
    
                    XERCES_STD_QUALIFIER cout << "Processing Namespace:   ";
                    const XMLCh *nameSpace = namespaces->elementAt(i);
                    if (nameSpace && *nameSpace)
                        XERCES_STD_QUALIFIER cout << StrX(nameSpace);
                    XERCES_STD_QUALIFIER cout << "\n============================================" << XERCES_STD_QUALIFIER endl << XERCES_STD_QUALIFIER endl;

                    processElements(xsModel->getComponentsByNamespace(XSConstants::ELEMENT_DECLARATION,
                                                                  nameSpace));
                    processTypeDefinitions(xsModel->getComponentsByNamespace(XSConstants::TYPE_DEFINITION,
                                                                         nameSpace));
                }   
            }
开发者ID:QEver,项目名称:vosproj,代码行数:67,代码来源:SCMPrint.cpp


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