Re: [xml] errors management
- From: Rush Manbert <rush manbert com>
- To: Francesco Gennai <francesco gennai isti cnr it>
- Cc: xml gnome org
- Subject: Re: [xml] errors management
- Date: Thu, 13 Nov 2008 10:44:29 -0800
On Nov 13, 2008, at 6:22 AM, 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?
If you are using libxml in a C++ program, it looks like you can use
the Boost Iostreams library to capture everything sent to std::cout or
std::cerr in an ostream buffer. I have not done this myself, but a
quick look at the library documentation made me think it was possible.
The FAQ mentions a tee_filter. My guess is that you could tee the
stderr streams into a buffer that you can examine. See http://www.boost.org/doc/libs/1_37_0/libs/iostreams/doc/index.html
Best regards,
Rush
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]