Re: [xml] question regarding error reporting



...
  if ((channel == xmlParserError) ||
        (channel == xmlParserWarning) ||
    (channel == xmlParserValidityError) ||
    (channel == xmlParserValidityWarning))
    xmlReportError(to, ctxt, str, NULL, NULL);
    else if ((channel == (xmlGenericErrorFunc) fprintf) ||
             (channel == xmlGenericErrorDefaultFunc))
    xmlReportError(to, ctxt, str, channel, data);
    else
    channel(data, "%s", str);
...


Is there a reason that xmlReportError isn't called regardless of what error
handler channel points to?

  I think that the point was to make a single callback in case a structured
error handler has been set-up (xmlReportError makes at least 2 calls IIRC).
The expectation is that the structured error handler will find informations
like the source file and line number from data or the global error variable.
I.e. fprintf is not a structured error reporting mechanism, it's string
based,
so it can be called multiple times for one error, on the other hand the user
callback is structured and should be called only once per error. I think it's
the reason for this dichotomy.


Hmmm... fprintf isn't a stuctured error handler, but neither is channel.  I
believe by the time this segment is reached the search for a structured error
handler to report the message has been exhausted and there doesn't seem to be a
means to use custom structured error handlers within relaxng validation.  As
such there seems to be a "information penalty" when when using custom error
handlers and the error domain isn't parsing or validating (those seem to be
handled specially).

So if I understand your explanation correctly the goal is to only call channel
once per xmlRaiseError call unless the handler happens to be fprintf (as such
libxml2 knows that it is not a problem call it repeatedly per call to
__xmlRaiseError)?  If so perhaps __xmlRaiseError can instead call
xmlReportError2 that would emulate xmlReportError only building the output to a
string then calling channel just once?




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