gpt4 book ai didi

c++ - 如何使用 Xerces 检查 XML 格式是否正确

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:14:43 24 4
gpt4 key购买 nike

我正在使用 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 );
}

最佳答案

您应该使用 WFXMLScanner 扫描仪仅执行格式良好性检查。 There are great examples关于如何将特定扫描仪与 xerces 结合使用。

关于c++ - 如何使用 Xerces 检查 XML 格式是否正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35303137/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com