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



Daniel Veillard wrote:
On Wed, Jul 28, 2004 at 10:31:23AM +0200, Martijn Faassen wrote:

Daniel Veillard wrote:

Since doc1 and doc2 are not sharing their dictionnary, yes you have a problem.
If you're starting to move nodes between documents like that you can either
desactivate dictionnaries or make sure they share dictionnaries. Use one of
the more recent APIs like xmlReadDoc() and set XML_PARSE_NODICT option.

Thanks for the info. I need to investigate the use of dictionaries then. Is that the only thing that can trip me up? Igor elsewhere in the threat mentions namespaces, for instance. I presume this is because libxml2 doesn't actually store namespace URIs in the nodes but does a look up based on prefix, or do I understand that wrong?


  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?

Regards,

Martijn



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