Re: [xml] propper error reporting

On Tue, Jan 09, 2007 at 02:53:20PM +0100, Petr Pajas wrote:
Hi Daniel, All,

I'm struggling with fixing error reporting from RelaxNG validation 
in the Perl XML::LibXML bindings. I would like to get a flat 
string, actually the very same string that xmllint spits only in 
memory, not on stderr. 

The problem is that if I use xmlRelaxNGSetValidErrors (like xmllint 
does, only with a different function than fprintf), my handler does 
not get the filename and line number of the error. So basically, if 
I use fprintf as my handler (like xmllint), the info is there, but 
if I e.g. wrap vsprintf in my own function, the info is absent.

I assume that this is because __xmlRaiseError makes itself this 

    else if ((channel == (xmlGenericErrorFunc) fprintf) ||
             (channel == xmlGenericErrorDefaultFunc))
        xmlReportError(to, ctxt, str, channel, data);
        channel(data, "%s", str);

So, fprintf and xmlGenericErrorDefaultFunc get the full message 
produced by xmlReportError, while other (flat) channels only get 

  Some clients wanted messages in one string which xmlReportError
doesn't do it output it in multiple chunks (for example they emitted 
a network packet on each callback on the channel). When we see fprintf or
the default function we know that this is not a problem and go ahead.

So my next idea was to use xmlRelaxNGSetValidStructuredErrors and do 
something like

xmlReportError(error, NULL, error->message, my_flat_channel, 

to create a formatted error message (exactly the same as that of 
xmllint) and pass it to my error reporting code.

However, xmlReportError is static, so that won't work. So my 
question is: is there any public API that would produce formatted 
error strings from xmlError or do I need to copy-paste the insides 
of xmlReportError to my code?

  People want flexibility, so there is the structured error API which 
gives all the pieces and let them rearrange their messaging as they want.
Use the structured error API, which should work with RNG too. That's the
only way to cope with the various conflicting requirements that people
put on error reporting.
  You could also somehow copy xmlReportError() too in your own code if
you don't want to switch to the new APIs.

Also, is there any actual reason for 
the distinction in __xmlRaiseError? Why would fprintf and some 
channel want to get different strings?

  See before.


Red Hat Virtualization group
Daniel Veillard      | virtualization library
veillard redhat com  | libxml GNOME XML XSLT toolkit | Rpmfind RPM search engine

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