本文介绍了Xerces-c:使用xsd文件C ++进行XML文件验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Xerces-c.我有一个.xsd方案,想用它来验证XML文件.我已经定义了xsd文件和错误处理程序,但是由于某种原因,xsd不会引发错误.对我可能会缺少的东西有什么见识?

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;
    }

谢谢.

推荐答案

当您说没有看到错误时,您是什么意思?您是否希望引发异常?如果这是您的期望,则不会发生这种情况,因为您已按如下所示设置了ErrorHandler.尝试实现其中的方法以将错误输出到控制台.同时发布您的XSD和XML

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);

这篇关于Xerces-c:使用xsd文件C ++进行XML文件验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-26 20:01
查看更多