Hi y'all,
I am trying to do validation of xml files against their schema using the Xerces library. I am expecting to get an exception while calling DOMParser::parse method when the xml file is invalid, i.e. it doesn't conform to its schema, but I don't get any exception. What am I doing wrong?
Following is snippet of my code:
------------------------------------------------------------------------------
int main(int argc, char* argv[])
{
try {
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch) {
cout << "Error during initialization! :\n"
<< DOMString(toCatch.getMessage()) << endl;
return 1;
}
string xml_file = "test.xml";
bool valid = true;
try
{
DOMParser* parser = new DOMParser;
parser->setDoNamespaces(true);
parser->setDoSchema(true);
parser->setValidationSchemaFullChecking(true);
parser->setValidationConstraintFatal(true);
ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase();
parser->setErrorHandler(errHandler);
parser->parse(xml_file.c_str());
delete errHandler;
delete parser;
}
catch (...) {
cout << "An error occurred during parsing" << endl;
valid = false;
}
cout << "The xml file is " << ( valid ? "valid" : "invalid" ) << endl;
XMLPlatformUtils::Terminate();
return 0;
}
------------------------------------------------------------------------------
Thank you for your replies.
Vikas
************************************************************************** The information transmitted herewith is sensitive information intended only for use by the individual or entity to which it is addressed. If the reader of this message is not the intended recipient, you are hereby notified that any review, retransmission, dissemination, distribution, copying or other use of, or taking of any action in reliance upon this information is strictly prohibited. If you have received this communication in error, please contact the sender and delete the material from your computer.