Xerces-c: XML file validation with xsd file c++

荒凉一梦 提交于 2019-12-24 07:58:11

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/4541064/xerces-c-xml-file-validation-with-xsd-file-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!