Re: XML libs (was Re: gconf backend)



Havoc Pennington wrote:

 Well libxml2 uses callback for errors, that's the model everybody
uses and I'm not sure that was ever questionned by the relatively large
user base. Since your model seems to impose an asynchronous processing
I think this will need some discussion on the mailing-list. I cannot
change radically to a new model without at list a bit of explanation.


Basically I want to write a function:

 MyAppDataStructure*  load_xml_file (const char *filename, GError
**error);

So the question is how to do that. 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.

What you want to display for a parse error is the line where the error
happened and a problem description; for an I/O error you want strerror
(errno). GError/DBusError/CORBA_environment/C++exceptions are a way to
propagate this detailed information.

Not that I really advocate doing this for libxml2; it seems like it
would basically double your API size by adding
xmlLoadACatalogWithError() and so forth. I _don't_ think this is a good
idea, for the record.


So basicly you want a simple function that would do all and any boilerplate you would ever need (including turning off going to network if you haven't specifly told it it may do so) gives you GError feedback when something goes wrong and from then on lets you deal with the input just as if it was a flat stream of bytes which might be xml? The only not trivialy copy-paste part in that is dealing with GError.


Havoc





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