Re: [xml] errors management

On Nov 13, 2008, at 6:22 AM, Francesco Gennai wrote:


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)) {
                       "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?


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

Best regards,

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