Schema validation using Xerces-C++ version 1.6.0?

V

Vikas

Sorry if I posted it twice. I posted the same question yesterday but I
don't see it yet. Following is my question...

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top