【问题标题】:Error preparsing a xsd file with xercesc使用 xercesc 准备 xsd 文件时出错
【发布时间】:2014-10-23 22:56:42
【问题描述】:

我正在尝试使用 xerces-c 准备 xsd 文件以在多线程应用程序中使用 GrammarPool。问题是我正确地预解析了 xsd(没有人通知我的错误处理程序)但是当我解析一个有效的 xml 文件(使用在线验证器检查是否有效)时,解析失败告诉我属性和元素尚未声明. 现在我将向您展示我的代码来预解析文件。

XMLGrammarPool gp = new XMLGrammarPoolImpl (XMLPlatformUtils::fgMemoryManager);
XercesDOMParser* parser = new XercesDOMParser(0, XMLPlatformUtils::fgMemoryManager, gp);
parser->cacheGrammarFromParse(true);
error_handler eh;
parser->setErrorHandler(&eh);
parser->setDoSchema(true);
parser->setDoNamespaces(true);
if(!parser->loadGrammar("file.xsd", Grammar::SchemaGrammarType, true) || eh.failed()){
    delete gp;
    XMLPlatformUtils::Terminate();
    return -6;
}
gp->lockPool();

这是用于解析 xml 文件:

XercesDOMParser *parser = new XercesDOMParser(0, XMLPlatformUtils::fgMemoryManager, gp);
error_handler eh;
parser->setErrorHandler(&eh);

parser->setValidationSchemaFullChecking(true);
parser->setIgnoreAnnotations(true);
parser->setCreateCommentNodes(false);
parser->useCachedGrammarInParse(true);
parser->setValidationScheme(AbstractDOMParser::ValSchemes::Val_Always);

MemBufInputSource buf((const XMLByte*)xml_file, size, "xml_file in memory");

parser->parse(buf);
if(eh.failed()){
    delete parser;
    return;
}

请帮忙!

【问题讨论】:

    标签: c++ xerces-c


    【解决方案1】:

    博客条目

    Multi-threaded XML parsing with Xerces-C++

    解释了如何在多线程应用程序中重用缓存模式。该博客名为A Sense of Design,由 Boris Kolpackov 撰写。

    我还建议您查看这个 Public Domain C++ 文件(也是同一作者)

    http://scm.codesynthesis.com/?p=xsd/xsd.git;a=blob;f=examples/cxx/tree/performance/parsing.cxx;hb=HEAD

    它向我们展示了如何让 Xerces 解析模式一次,然后读取多个 XML 文件。实现的某些部分与CodeSynthesis XSD 相关,因此您需要对其进行一些修改。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-13
      • 1970-01-01
      • 2012-05-18
      • 2017-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多