Tim Cramer wrote:
Hello everyone,
i have got a problem with the validation with a schema. I am using the
DOMBuilder, which has a DOMErrorHandler. When I try parsing a invalid
document, it is only parsed up to the wrong element, value, etc without
any error message / exception. How can I handle a schema error? I set
the features the following way:
DOMBuilder* probParser_ =
impl->createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS,0);
XNSQ DOMErrorHandler* errHandler = (DOMErrorHandler*) new XNSQ
HandlerBase();
This cast should not be necessary. Is there some reason it's there?
probParser_->setErrorHandler(errHandler);
probParser_->setProperty(
XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation,
"file.xsd" );
probParser_->setFeature( XMLUni::fgDOMNamespaces, true);
probParser_->setFeature( XMLUni::fgXercesSchema, true);
probParser_->setFeature( XMLUni::fgXercesSchemaFullChecking, true);
What happens if you set this feature:
probParser_->setFeature( XMLUni::fgDOMValidateIfSchema, true);
you might also try:
probParser_->setValidationScheme(AbstractDOMParser::Val_Always);
try{
XNSQ DOMDocument* newProblem = probParser_->parse(sourceWrapper);
; }
catch(const XMLException& toCatch){
char* message = XNSQ XMLString::transcode(toCatch.getMessage());
std::cerr << "Parsing Error.XML Exception message is:\n"
<< message << "\nPlease check your Problemfile!\n";
XNSQ XMLString::release(&message);
return false;
}
catch(const DOMException& toCatch){
char* message = XNSQ XMLString::transcode(toCatch.msg);
std::cerr << "Parsing Error. DOM Exception message is:\n"
<< message << std::endl;
XNSQ XMLString::release(&message); }
catch(const SAXException& toCatch){
std::cerr << "error\n";
}
catch(...){
;//...
}
I hope your error handler is actually throwing the exceptions it receives.
Otherwise, they will just be swallowed. Since you didn't provide any
source code for your ErrorHandler, we can only guess.
Dave