[xml] propper error reporting

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 

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? Also, is there any actual reason for 
the distinction in __xmlRaiseError? Why would fprintf and some 
channel want to get different strings?

-- Petr

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