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


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

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


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

示例1: main

int main(int argc, char **argv)
{
  bool verbose = false;
#if 0
  DOMParser::ValSchemes    gValScheme             = DOMParser::Val_Auto;
  bool                     gDoNamespaces          = true;
  bool                     gDoSchema              = true;
  bool                     gSchemaFullChecking    = false;
  bool                     gDoCreate              = false;
#endif

  MFileOperations f;
  char path[1024];

  f.expandPath(path, "MESA_TARGET", "runtime");
  ::strcat(path, "/IHE-syslog-audit-message-4.xsd");
  char* schemaDef = path;

  int detailLevel = 1;
  MString tmp;

  while (--argc > 0 && (*++argv)[0] == '-') {
    switch (*(argv[0] + 1)) {
    case 'l':
      argc--; argv++;
      if (argc < 1)
	usage();
      tmp = *argv;
      detailLevel = tmp.intData();
      break;
    case 's':
      argc--; argv++;
      if (argc < 1)
	usage();
      schemaDef = *argv;
      break;
    case 'v':
      verbose = true;
      break;
    default:
      break;
    }
  }

  if (argc < 1)
    usage();

  // Initialize the XML4C2 system
  try {
    XMLPlatformUtils::Initialize();
  }
  catch (const XMLException& e) {
    cout << "Unable to initialize Xerces-c software"
	 << DOMString(e.getMessage()) << endl;
    return 1;
  }


  DOMParser *parser = new DOMParser;
  parser->setValidationScheme(DOMParser::Val_Auto);
  parser->setDoNamespaces(true);
  parser->setDoSchema(true);
  parser->setValidationSchemaFullChecking(true);
  if (schemaDef != "") {
    parser->setExternalNoNamespaceSchemaLocation(schemaDef);
  }

  DOMTreeErrorReporter *errReporter = new DOMTreeErrorReporter();
  parser->setErrorHandler(errReporter);
  parser->setCreateEntityReferenceNodes(false);
  parser->setToCreateXMLDeclTypeNode(true);

  bool errorFlag = false;

  try {
    parser->parse(*argv);
    int count = parser->getErrorCount();
    if (count > 0) {
      errorFlag = true;
      return 1;
    }
  }
  catch (const XMLException& e) {
    cout << "Parsing error: " << DOMString(e.getMessage()) << endl;
    return 1;
  }
  catch (const DOM_DOMException& e) {
   cout << "DOM Error: " << e.code << endl;
   return 1;
  }

  catch (...) {
    cout << "Unspecified error" << endl;
    return 1;
  }

  DOM_Document doc = parser->getDocument();

  unsigned int elementCount = doc.getElementsByTagName("*").getLength();

//.........这里部分代码省略.........
开发者ID:nagyistge,项目名称:mesa,代码行数:101,代码来源:mesa_xml_eval.cpp

示例2: main


//.........这里部分代码省略.........
            doList = true;
        }
         else if (!strncmp(argV[argInd], "-r=", 3)
              ||  !strncmp(argV[argInd], "-R=", 3))
        {
            const char* const numStr = &argV[argInd][3];
            XMLCh* numXStr = XMLString::transcode(numStr);
            numReps = XMLString::parseInt(numXStr);
            XMLString::release(&numXStr);
        }
         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;
    }

    // Instantiate the DOM domBuilder with its memory manager.
    MemoryMonitor *domBuilderMemMonitor = new MemoryMonitor();
    static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull };
    DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(gLS);
    DOMBuilder        *domBuilder = ((DOMImplementationLS*)impl)->createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS, 0, domBuilderMemMonitor);
    DOMBuilderHandler domBuilderHandler;
    domBuilder->setErrorHandler(&domBuilderHandler);

    // Instantiate the SAX2 domBuilder with its memory manager.
    MemoryMonitor *sax2MemMonitor = new MemoryMonitor();
    SAX2XMLReader *sax2parser = XMLReaderFactory::createXMLReader(sax2MemMonitor);
    SAXErrorHandler saxErrorHandler;
    sax2parser->setErrorHandler(&saxErrorHandler);

    // Instantiate the deprecated DOM parser with its memory manager.
    MemoryMonitor *depDOMMemMonitor = new MemoryMonitor();
    DOMParser *depDOMParser = new (depDOMMemMonitor)DOMParser(0, depDOMMemMonitor);
    depDOMParser->setErrorHandler(&saxErrorHandler);

    // Instantiate the SAX 1 parser with its memory manager.
    MemoryMonitor *sax1MemMonitor = new MemoryMonitor();
    SAXParser *saxParser = new (sax1MemMonitor) SAXParser(0, sax1MemMonitor);
    saxParser->setErrorHandler(&saxErrorHandler);

    // set features 
    domBuilder->setFeature(XMLUni::fgDOMNamespaces, doNamespaces);
    sax2parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, doNamespaces);
    depDOMParser->setDoNamespaces(doNamespaces);
    saxParser->setDoNamespaces(doNamespaces);

    domBuilder->setFeature(XMLUni::fgXercesSchema, doSchema);
    sax2parser->setFeature(XMLUni::fgXercesSchema, doSchema);
    depDOMParser->setDoSchema(doSchema);
    saxParser->setDoSchema(doSchema);

    domBuilder->setFeature(XMLUni::fgXercesSchemaFullChecking, schemaFullChecking);
    sax2parser->setFeature(XMLUni::fgXercesSchemaFullChecking, schemaFullChecking);
    depDOMParser->setValidationSchemaFullChecking(schemaFullChecking);
    saxParser->setValidationSchemaFullChecking(schemaFullChecking);
开发者ID:ksmyth,项目名称:xerces-c,代码行数:67,代码来源:MemoryMonitor.cpp


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