Xerces-c:使用 xsd 文件 c++ 进行 XML 文件验证

发布于 2024-10-09 08:11:15 字数 779 浏览 0 评论 0原文

我正在尝试使用 Xerces-c。我有一个 .xsd 方案并想用它来验证 XML 文件。我已经定义了 xsd 文件和错误处理程序,但由于某种原因 xsd 没有抛出错误。对我可能缺少的内容有什么见解吗?

    XercesDOMParser* parser = new XercesDOMParser();
    parser->setExternalNoNamespaceSchemaLocation("parser.xsd");
    parser->setExitOnFirstFatalError(true);
    parser->setValidationConstraintFatal(true);
    parser->setValidationScheme(XercesDOMParser::Val_Auto);
    parser->setDoNamespaces(true);    
    parser->setDoSchema(true);      

    ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase();
    parser->setErrorHandler(errHandler);

    char* xmlFile = "sample.xml";

    try {
         ....
    } catch (const DOMException& e) {
         cout << "Exception.." << endl;
    }

谢谢。

I am attempting to use Xerces-c. I have a .xsd scheme and want to use it to to validate an XML file. I've define the xsd file and an error handler, but for some reason the xsd is not throwing errors. Any insights to what I may be missing?

    XercesDOMParser* parser = new XercesDOMParser();
    parser->setExternalNoNamespaceSchemaLocation("parser.xsd");
    parser->setExitOnFirstFatalError(true);
    parser->setValidationConstraintFatal(true);
    parser->setValidationScheme(XercesDOMParser::Val_Auto);
    parser->setDoNamespaces(true);    
    parser->setDoSchema(true);      

    ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase();
    parser->setErrorHandler(errHandler);

    char* xmlFile = "sample.xml";

    try {
         ....
    } catch (const DOMException& e) {
         cout << "Exception.." << endl;
    }

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

森林很绿却致人迷途 2024-10-16 08:11:15

当您说没有看到错误时是什么意思?您是否期望抛出异常?如果这是您的期望,那么这种情况不会发生,因为您已按如下方式设置 ErrorHandler。尝试实现其中的方法以将错误打印到控制台。还发布您的 XSD 和 XML

parser->setErrorHandler(errHandler);

What do you mean when you say you are not seeing errors? Are you expecting an exception to be thrown? If that is your expectation then this will not happen because you have set the ErrorHandler as below. Try implementing the methods in it to print errors to the console. Also post your XSD and XML

parser->setErrorHandler(errHandler);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文