问题
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