Re: [xml] using xmlDocSetRootElement to move nodes between documents

Daniel Veillard wrote:
On Wed, Jul 28, 2004 at 11:50:00AM +0200, Martijn Faassen wrote:

You are right. There have been attempts to solve this with xmlReconciliateNs in tree.c this should solve namespace problems.
Other potential problem is entities references.

So basically the conclusion is that there is no safe way to move
nodes between documents in libxml2 at this point in time? I don't
mind having to call some function to 'import' nodes into a
different tree, but it seems I have to worry about namespaces,
dictionaries and entities at least. Right now I'm using
xmlDocCopyNode(), which appears to work, isn't the right semantics
for the API I'm trying to implement, which allows free movements of
elements between trees.

What would a function look like that that can be used to safely
import a node (and its subnodes) from one document to another?
Could this function do its work relatively efficiently?

The efficiency is the problem. Recursing down the subtree generate
cost. It's possible to share dictionaries for multiple documents,
it's possible to reconciliate namespaces, but entities if not
substitued on parse are a serious problem, you may have to add them
on the internal subset of the target.

This is putting a lot of the burden on the way the documents are
created. Wouldn't it still be useful to have a function that did the
right thing (even if it's relatively slow) when moving nodes from one
document to another?

Anyway, I guess to implement this API I'll have to go about some other

By the way, am I correct in assuming that xmlFreeDoc does not remove any nodes that are in that document but not attached to it? I.e. free nodes that have just been created but not yet attached, or nodes that are unlinked, are not freed, right?



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