Vikas (archive)
Usenet Archive
- Joined
- Feb 8, 2001
- Messages
- 44
- Reaction score
- 0
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:
arse 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
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:
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