[xml] RE: xmlSetGenericErrorFunc

Date view Thread view Subject view Author view

From: Leo Davidson (leo@ox.compsoc.net)
Date: Sun Nov 19 2000 - 17:33:01 EST


To follow-up on this, two more things:

1) When I said you could call
        xmlSetGenericErrorFunc(stderr, xmlGenericErrorDefaultFunc)
I was wrong since xmlGenericErrorDefaultFunc isn't available outside of
LibXml's error.c, so as far as I can tell (maybe I'm being stupid!) there's
no way to restore the default error handling, FWIW.

2) The error handler set by xmlSetGenericErrorFunc doesn't seem to get
called very predicably... The documentation says it's called outside of
parsing and validation, but it seems to be called during parsing as well,
although not for as many events.

For example...

Without changing the error handler I get error messages like this when
calling xmlParseFile on a file which has an error:

--8<--
C:\SN_Devices.xml:5: error: error parsing attribute name
      <DigitsToPadTo Number="1"/>
      ^
-->8--

If I set an error handler, that handler only gets part of the error message:

--8<--
C:\Leo\source\Home\SuperNudelist\Debug\SN_Config\SN_Devices.xml:5: error:
<DigitsToPadTo Number="1"/>
      ^
-->8--

(Missing the " error parsing attribute name<return>")

Is this a bug?

If it's not a bug, is there any way to call xmlParseFile (I'm not using SAX)
and capture all error messages? I'm writing a GUI application and error
messages that go to stderr/stdout won't be seen by anyone. :-(

Thanks for your time!

        Leo

> -----Original Message-----
> From: Leo Davidson [mailto:leo@ox.compsoc.net]
> Sent: Sunday, November 19 2000 19:40
> To: List LibXml Alt (E-mail)
> Subject: xmlSetGenericErrorFunc
>
> (Apologies if this has changed in 2.2.8 as I am still working
> with 2.2.7 at
> the moment.)
>
> Just a quick comment on xmlSetGenericErrorFunc: Since it
> ignores any NULL
> arguments (ctx or handler), there's (a) no way to specify a
> NULL ctx if
> that's what you really want and (b) no way to revert back to
> the default
> handling.
>
> (a) Could be important if your error handler optionally uses ctx but
> requires it NULL at other times. (I guess you could have two separate
> handler functions, one which ignores ctx... but why is
> setting ctx to NULL
> bad or any different to setting it to any other value?)
>
> (b) Can be worked around by calling
> xmlSetGenericErrorFunc(stderr, xmlGenericErrorDefaultFunc)
> but that assumes that the default won't ever change.
>
> Why not change xmlSetGenericErrorFunc to:
>
> void
> xmlSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler)
> {
> // Always set ctx as requested.
> xmlGenericErrorContext = ctx;
>
> // Set handler as requested, or restore default if NULL.
> if (handler != NULL)
> xmlGenericError = handler;
> else
> xmlGenericError = xmlGenericErrorDefaultFunc;
> }
>
> Of course, this assumes that if handler is NULL then either
> ctx is also NULL
> or the caller has set ctx to a FILE*. If that assumption
> doesn't hold then
> the default handler will crash.
>
> Sorry if this is a stupid idea!
>
> Leo
>
> --
>
>

----
Message from the list xml@rpmfind.net
Archived at : http://xmlsoft.org/messages/
to unsubscribe: echo "unsubscribe xml" | mail  majordomo@rpmfind.net


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Sun Nov 19 2000 - 17:43:32 EST