Re: [xml] docs and dicts in xmlSetTreeDoc()



On Fri, May 02, 2008 at 06:06:41PM +0200, Stefan Behnel wrote:
Hi,

I've just fixed a long-standing problem in lxml, now I'm wondering if it isn't
actually a problem in libxml2. The function xmlSetTreeDoc() in tree.c is
called to update the xmlDoc* pointers of each node in a subtree when it gets
appended to a new parent in a different document. The question is: should this
function also re-assign the "name" pointers of the nodes if both documents use
a dict and the dictionary of the target document is different from the
dictionary of the source tree?

The decision is easy to take (compare the dict pointers of both documents) and
the code to re-assign the name is simple: call xmlDictLookup() and re-assign
the name of the node to the result. In addition, a call to
xmlDictOwns(old_dict, old_name) might be necessary to see if the old name must
be freed.

Would this be considered worth changing? Or are there any reasons not to do
this? There obviously is a performance impact, but I consider it the correct
thing to do if both documents are meant to be independent afterwards.

  yes there is a performance impact for doing so. Still this may make sense,
though for applications which copy tree fragments around, it's best to use
the XML_PARSE_NODICT parsing option and limit the contextual dependancies
for nodes (limit, not remove, entities and namespace references come to mind).

Daniel

-- 
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard      | virtualization library  http://libvirt.org/
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]