Re: [xml] errors management
- From: Francesco Gennai <francesco gennai isti cnr it>
- To: Gait Boxman <gait boxman tie nl>
- Cc: xml gnome org
- Subject: Re: [xml] errors management
- Date: Fri, 14 Nov 2008 10:55:49 +0100
Hi,
I followed your good suggestion, thank you, but now I have a new slight
problem.
I hope that someone on the list can help me....
I have setup xmlSetGenericErrorFunc.
When the errors come from (for example)
pdoc = xmlReadFile(xmlFile, NULL, 0);
or
pdtd = xmlParseDTD(NULL, (const xmlChar *)dtdFile);
the single error line doesn't terminate with a line separator (LF)
and the result is that when they are concatenated in the
errorbuffer your are no more able to recognize each single line.
This is an example of output from errorbuffer:
No such file or directoryI/O warning : failed to load external entity "doc.dt"
when the errors come from xmlValidateDtd(&pctxt, pdoc, pdtd)
it works fine (the single error line are terminated by a LF),
but in this case I initialize the following structure:
pctxt.userData = (void *) NULL;
pctxt.error = (xmlValidityErrorFunc) my_errorhandler;
pctxt.warning = (xmlValidityWarningFunc) my_errorhandler;
before to call
xmlValidateDtd(&pctxt, pdoc, pdtd)
Here is the code that I'm using as xmlSetGenericErrorFunc
(extracted from RUNSUITE.C)
static char errorbuffer[32769];
static int errorbufferlen = 0;
static void my_errorhandler(void *ebuf, const char *fmt, ...) {
int ret = 0;
va_list argp;
if (errorbufferlen >= 32768)
return;
va_start(argp, fmt);
ret = vsnprintf(&errorbuffer[errorbufferlen],
32768 - errorbufferlen,
fmt, argp);
va_end(argp);
if (errorbufferlen + ret >= 32768) {
/* buffer is full */
errorbufferlen = 32768;
errorbuffer[errorbufferlen] = '\0';
} else {
errorbufferlen += ret;
}
errorbuffer[errorbufferlen] = '\0';
return;
}
Any help?
Francesco
Hi,
you'll need to write your own function that mimics fprintf, but which
appends to a chars array (or may be an array of char arrays).
As far as the buffer size is concerned: single buffer should be big
enough to hold the longest message, or you need to mimic fprintf's
capability to dynamically compute the buffer size.
4096 chars for a single should be sufficient though.
google for fprintf source code, you should find some, if only in the
Linux stdio sources.
--Gait.
Francesco Gennai wrote:
Hi,
I would like to capture any error from LIBXML API
and (if possible) have it in memory to process it
in my own error/debug routines.
Here is an example of code that can returns more than one error line.
pctxt.userData = (void *) stderr;
pctxt.error = (xmlValidityErrorFunc) fprintf;
pctxt.warning = (xmlValidityWarningFunc) fprintf;
if (!xmlValidateDtd(&pctxt, pdoc, pdtd)) {
xmlGenericError(xmlGenericErrorContext,
"Document %s does not validate against %s\n",
xmlFile, dtdFile);
such as:
No declaration for element dst
No declaration for attribute id of element dst
attribute ref line 5 references an unknown ID "foo"
attribute ref line 7 references an unknown ID "foo"
I would like an example how to modify the above code to capture
the error lines in some memory structure (chars array, ....).
Is it possible?
I suppose that it needs to write a function (like *printf functions)
to call in place of fprintf (in the above example).
Is there any example of code?
Francesco
I tried by changing fprintf with sprintf and stderr with (outerr) a character
string, but in this case I get
- only one line of the above errors
- I have the problem... how much length should be outerr chars array?
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
xml gnome org
http://mail.gnome.org/mailman/listinfo/xml
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]