【问题标题】:How to check if XML is well formed with Xerces如何使用 Xerces 检查 XML 格式是否正确
【发布时间】:2016-02-09 22:05:56
【问题描述】:

我正在使用 Xerces C++ 库来解析 XML。我需要一个函数来确定输入的 XML 格式是否正确。 DOMConfiguration Interface 中提到了“格式良好”,但没有说明如何使用它。

这就是我的代码到目前为止的样子。无论 XML 格式是否正确,它的工作原理都是一样的,但我需要知道它何时格式不正确。

try {
    XMLPlatformUtils::Initialize();
    // create the DOM parser
    XercesDOMParser *parser = new XercesDOMParser;
    parser->setValidationScheme(XercesDOMParser::Val_Never);
    parser->parse(xml_input.c_str()); // where xml_input is my XML filename

    // get the DOM representation
    DOMDocument *doc = parser->getDocument();
    // get the root element
    DOMElement *root = doc->getDocumentElement();

}
catch ( DOMXPathException& e )
{
    char* message = xercesc::XMLString::transcode( e.getMessage() );
    cout << message << endl;
    XMLString::release( &message );
}

【问题讨论】:

    标签: c++ xml xerces


    【解决方案1】:

    您应该只使用 WFXMLScanner 扫描程序来执行格式良好的检查。 There are great examples 了解如何将特定扫描仪与 xerces 一起使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-04-03
      • 1970-01-01
      • 2010-10-01
      • 2018-01-17
      • 1970-01-01
      • 1970-01-01
      • 2012-06-06
      相关资源
      最近更新 更多