Re: [xml] A generic way to add user data to nodes?



On Thu, Jan 10, 2002 at 02:45:40PM +0100, Simon Berg wrote:
Hi, everybody

I feel that it would be useful if libxml had a generic way to add user data
to nodes. Right no fighting over the _private field or using external 
lookup tables seems to be the only options.

  Fighting over ? Why ? this field is left to the application for use.

Using the content field to store line numbers also seems a bit awkward.

  Yes, but I didn't found any other way to add it without breaking
clients API and bnary compatibility.

This is my suggestion how a solution might look:
[...]
The _private field is used to point to the first user data object.

  This is an access convention. Since the field is left to the user
program that convention could be followed or not. In that case why
try to impose it ?

The xmlNew* functions would have to be changed to initialize _private
to NULL.

  No they already do. Well they should. If it's not the case it's a bug.

xmlFreeNode needs to call the release method on all attached user
data objects. Should the release callback be called on all super classes too,
like a C++ destructor?

  Hum, 

xmlCopyNode should call the copy method on all attached data.

  I can perfectly see case where this should NOT be done. For example
_private is used for node key indexing in libxslt and a copied node
should not be considered as a keyed node. User level semantic !

There are probably other functions that need modification too.

How does this work with threads?

  requires user level locking like every other tree access function.

What do you think? Is this a good idea? In the long run it would
require to rewrite some amounts of code, but I still think this kind
of solution is the way to go.

  Unclear to me. I have considered it, and while sometimes I would like
an extensible framework, I also hate over-engineering and it's unclear to
me this is really needed. Anyway this would have to be pushed to a later
binary incompatible revision I'm afraid.

Daniel

-- 
Daniel Veillard      | Red Hat Network https://rhn.redhat.com/
veillard redhat com  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/



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