Hi All,
I am using XercesDOMParser to parse xml file with validation turn on. With
following snippets of code
std::auto_ptr<xercesc::XercesDOMParser> parser(new xercesc::XercesDOMParser(0,
xercesc::XMLPlatformUtils::fgMemoryManager,
grammar_pool));
parser->setDoNamespaces(true);
parser->setValidationScheme(xercesc::XercesDOMParser::Val_Always);
parser->setDoSchema(true);
parser->setValidationSchemaFullChecking(true);
parser->setIncludeIgnorableWhitespace(false);
parser->setCreateCommentNodes(false);
parser->cacheGrammarFromParse(true);
parser->useCachedGrammarInParse(true);
parser->setLoadSchema(false);
parser->setHandleMultipleImports(true);
parser->setErrorHandler(&errhandler);
parser->parse(xml_buffer);
if (parser->getErrorCount() > 0)
{
//throw exception
}
Where errhandler is object of the following class
class ClgnDOMErrorHandler : public xercesc::ErrorHandler
{
public:
ClgnDOMErrorHandler()
{}
~ClgnDOMErrorHandler()
{}
void ClgnDOMErrorHandler::warning(const xercesc::SAXParseException&)
{
// Ignore all warnings.
}
void error(const xercesc::SAXParseException& toCatch)
{
// Throw proper exception
}
void fatalError(const xercesc::SAXParseException& toCatch)
{
// Throw proper exception
}
void ClgnDOMErrorHandler::resetErrors()
{
}
};
My problem is that if the input xml_buffer is not valid as per the schema(like
and tag is missing or tag is un terminated) then it properly goes to
errhandler's error function. But something weird is happening now and parse()
function is failing and its not going to errhandlers' error() function and
instead coming to
if (parser->getErrorCount() > 0). Though this condition was put here to trap
some unhandled error but now I am stuck how to know whats the error:)
Is there any way I can trap the exact error with parse() function.
Thanks & Regards
Gaurav Sharma
The information contained in this electronic mail transmission
may be privileged and confidential, and therefore, protected
from disclosure. If you have received this communication in
error, please notify us immediately by replying to this
message and deleting it from your computer without copying
or disclosing it.