Re: [xml] xmlAddChild and xmlUnlinkNode
- From: Nikolay Sivov <bunglehead gmail com>
- To: veillard redhat com
- Cc: xml gnome org
- Subject: Re: [xml] xmlAddChild and xmlUnlinkNode
- Date: Sun, 13 Mar 2011 03:32:38 +0300
On Sun, Mar 13, 2011 at 12:51:26AM +0300, Nikolay Sivov wrote:
Hi.
It seems to me that xmlAddChild behaviour is kinda unexpected when
you try to add a node that is altready linked to another document
(or node of another type). If you don't xmlUnlinkNode before add
call this results in node being referenced by both documents, so on
free is will fail (libc crash for me).
It's fine of course to always do xmlUnlinkNode no matter what but
what bothers me is that xmlAddChild has xmlSetTreeDoc() inside
that's called if new parent document doesn't match new child's doc.
So references are fixed for new node only with xmlSetTreeDoc but not
for old document it seems.
Does it sound reasonable to add xmlUnlinkNode in xmlAddChild or I
should always unlink manually?
I would suggest to unlink. The problem of the document reference
is that it's not only related to the normal parent/children relations
but for example the element subtree may use the source document
dictionary, or namespaces coming from the source. In general
pruning/grafting set of nodes from one document to another is a
complex operation, and I would be as cautious as possible.
Ok, keeping in mind library age better to unlink outside, I agree.
Thing is xmlAddPrevSibling does unlink itself, and add sibling and add
child are same level operations,
so I expected it to work the same way, nevermind.
Thanks.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]