RE: [xml] Error handling with the XmlReader API



  Hum, one of the key point of the error handler over SAX is that
the user code keep the control of the processing flow. The LastError
code seems better in this respect. However the C# binding is based on
exception and in general it's a good thing for error handling. For C
that's not possible. So let's keep a non-callback interface for error
handling too at that level.
  There is a few technical problems with the approach you suggest,
basically the error callbacks from the parser will not be synchronous
to the current node of the parser, hard to avoid technically. 
When doing
a Read() a 512 byte blob is parsed, and errors are reported at that 
point. Second problem is that there will be multiple error callbacks
at the SAX level for a single logical error, that can 
probably be handled
relatively cleanly though. Last when parsing a chunk multiple errors
may be raised during what's viewed from the reader interface 
as a single
step, so getting only the last message may prove too limited 
in practice.

  It's not that simple. The second interface seems more in-line with
the reader design, but the first interface would be simpler 
to implement
and probably more accurate.

  I can't really select one as being better than the other at 
this point,
what other people think, you included ?

Here are 2 more arguments to put in the balance.

First, my proposals lack locator information. That's probably easier
to add to the callback method than the getLastError approach.

Second, C# has a mechanism to use callbacks instead of exception to report
validation errors (the user can choose). For well-formedness
errors, exceptions are always thrown.

I guess one could conceive variations on the getLastError theme
to correlate errors with nodes but that would be complex to implement
and to use, IMO.

So I would vote for the callback approach, with locator information.

typedef void (*xmlTextReaderErrorFunc)(
   void *arg, const char *msg,
   int line, int col, const char *uri, int severity);

int xmlTextReaderSetErrorHandler(
   xmlTextReaderPtr reader, xmlTextReaderErrorFunc f, void *arg);

After all, I think it's not a good idea to give the xmlTextReaderPtr to
the callback, because when the callback is invoked, the reader
is not necessary in a valid state? 
However providing a user argument is probably necessary.

-sbi




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]