1

I am trying to use Xerces-C to parse XML with a validating XSD or DTD. Unfortunately, validation errors are not reported. Here's how I am setting it up:

saxParser = new MySAXParser;
saxParser->setDoNamespaces(true);
saxParser->setValidationScheme(MySAXParser::Val_Auto);
saxParser->setDoSchema(true);
saxParser->setValidationConstraintFatal(true);
saxParser->setExitOnFirstFatalError(true);
MySAXErrorHandler handler;
saxParser->setErrorHandler(&handler);
saxParser->parse(...);

Unfortunately, this method of my error handler is never called:

virtual void fatalError(const XN::SAXParseException &exc) { throw exc; }

When a validation error occurs, an internal Xerces method is called:

void XMLValidator::emitError(const XMLValid::Codes toEmit
, const XMLCh* const text1
, const XMLCh* const text2
, const XMLCh* const text3
, const XMLCh* const text4)

However, it gets here:

if (fErrorReporter)

but fErrorReporter is null, so nothing is reported. I would like to install an error reporter (it is of type XMLErrorReporter), where I could track the message and/or throw my own exception, but I don't know how to do that.

I can call saxParser->getErrorCount() and it returns non-zero, which is good. That let's me report "There was an error!". But the error text and position wasn't captured.

UPDATE: This is Xerces-c version 3.1

Note I've read this but it doesn't seem to work with SAX.

Community
  • 1
  • 1
Wheezil
  • 3,157
  • 1
  • 23
  • 36

1 Answers1

0

Derp, this was my mistake. My error handler object was built with:

class MySAXErrorHandler : public HandlerBase {
public:
    virtual void fatalError(const SAXParseException &exc) { throw exc; }
};

While structural errors are reported via fatalError(), validation errors are reported via error(). The HandlerBase class has a default implementation of error() to "do nothing". Overriding error() in addition to fatalError() solved the problem.

Wheezil
  • 3,157
  • 1
  • 23
  • 36