Re: [xml] Reparenting nodes across documents?
- From: Marco Rogers <marco rogers gmail com>
- To: veillard redhat com
- Cc: xml gnome org
- Subject: Re: [xml] Reparenting nodes across documents?
- Date: Thu, 5 Aug 2010 08:50:28 -0400
Awesome, this is the kind of information I need. ÂMost use cases for me and my users aren't this involved yet. ÂBut I definitely want to reach this level of sophistication. ÂJust have to decide where it goes on the priority list. ÂThanks Daniel.
I need to write some more tests to make sure Âthe behavior is consistent for the level it's at right now. ÂI'll likely be back with more targeted questions.
:Marco
On Thu, Aug 5, 2010 at 8:35 AM, Daniel Veillard
<veillard redhat com> wrote:
On Tue, Aug 03, 2010 at 11:10:24AM -0400, Marco Rogers wrote:
> I'm using manipulation functions like xmlAddChild and xmlAddNextSibiling in
> my _javascript_ binding library (
http://github.com/polotek/libxmljs). ÂI
> whenever I use these I have a function that checks whether the incoming new
> node is already a child of a different document and if so it does a node
> copy and destroys the old node. ÂI've now been told that this isn't
> necessary because functions like xmlAddChild already do this check and will
> do the document transfer for me. ÂIs this correct? ÂWhat other things should
> I take into account when transferring nodes across documents?
ÂIt's more complex than that...
Basically a subtree is linked Âto the main document by multiple things:
Â- the parent and doc pointers which are handled by xmlAddChild and
 Âthe like
Â- entity references will point to definitions in the DTD if used and
 Ânot replaced at parsing time
Â- the namespaces, that's far more complex, some element or attribute
 Âin the subtree may references namespaces defined in upper layer
 Âin the tree, that need to be carefully fixed, changing those
 Âpointers to equivalent namespaces definitions in the target
 ÂxmlReconciliateNs() tries to handle this too.
Â- dictionary, some strings like Names or short text strings are
 Âusually allocated from the document dictionnary at parse time
 Âunless you deactivate them, so if the source and target documents do
 Ânot share the same dictionaries, this will lead to crash at the time
 Âthe tree is freed, either disable dictionary use at parse time
 Âor make sure the documents share the same ditionnary
in general, even if moving subtrees from one document to
another sounds simple this is actually a very complex operation to
do right in all cases.
--
Marco Rogers
marco rogers gmail comLife is ten percent what happens to you and ninety percent how you respond to it.
- Lou Holtz
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]