Re: XML libs (was Re: gconf backend)
- From: Evan Martin <martine danga com>
- To: Havoc Pennington <hp redhat com>
- Cc: veillard redhat com, desktop-devel-list gnome org
- Subject: Re: XML libs (was Re: gconf backend)
- Date: Sun, 28 Sep 2003 01:57:31 -0700
On Sun, Sep 28, 2003 at 02:07:52AM -0400, Havoc Pennington wrote:
> Basically I want to write a function:
>
> MyAppDataStructure* load_xml_file (const char *filename, GError
> **error);
>
> So the question is how to do that.
Speaking as a random GTK/GNOME application developer, this is also
exactly what I need. In my app I have this 500-line source file that
just serializes a big struct to a configuration file, and I've created a
pile of macros/helper functions to get that done. (Yes, gconf, but my
users won't buy that.) The documents also follow a similar pattern.
For example, I never need to create a node that has a namespace or that
has mixed text and other subnodes. My helper functions are all like
getInt(doc, node, int *value) that call scary functions like
xmlNodeListGetString(doc, node->xmlChildrenNode, TRUE); (plus the atoi
and the xmlFree). I don't even remember what the TRUE means.
I appreciate that XML is complicated and I'm glad that libxml handles
everything, but as an application developer that just needs a simple
serialization format I'm really seeing Havoc's point.
> The problem is that functions such as xmlLoadACatalog() (totally
> random example) don't return any explanation of the error; you can
> look at errno, but you don't know if the errno is for stat() or open()
> or read() or there could be a parse error or out-of-memory and errno
> is junk. So the only possible error to display to the user is "failed
> to load catalog" or something, with no further diagnostic. Also,
> sometimes on failure it looks to me like xmlGenericError was called
> and sometimes it wasn't.
I've also ran into problems handling errors, though I can't remember the
details. Here's the comment from the code that uses libxml to check
a block of text as valid xml.
/* it appears there's no way to attach a pointer to a libXML
* parser context, which means we need to use a global variable
* so we can save the error message it tries to print to stdout
* and display it in a dialog instead. as another hack, we need
* to display that text in a monospaced font because it highlights
* the invalid character position...
*/
static GString *xml_error_context_hack;
and then in the code that uses that:
xml_error_context_hack = g_string_new(NULL);
xmlSetGenericErrorFunc(ctxt, myxmlErrFunc);
[...]
initGenericErrorDefaultFunc(NULL);
xmlFreeParserCtxt(ctxt);
g_string_free(xml_error_context_hack, TRUE);
(This is probably the wrong place to bring it up, but it seemed
relevant. I don't mean to just flame libxml-- I use it all the time--
but I did want to reinforce both of Havoc's points.)
--
Evan Martin
martine danga com
http://neugierig.org
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]