Hi there,

I recently had an issue with xmlAddChild and xmlCopyNode which I solved but
still try to understand.

What I did was creating a new subtree and afterwards inserting it into an
existing tree.
So after creating a new node and some children I inserted it into the
existing tree via:
tmpNodePtr = xmlAddChild(parentNodePtr, xmlCopyNode(newNodePtr, 1));

I used xmlCopyNode because the nodes where newly declared within that
function and I assumed the pointers would be invalid as soon as I leave that
function.

The real issue I had was that the namespace of the new node got lost due to
the copy (tmpNodePtr->ns is NULL). I don't understand why, since I have
given the option "1" which should do a recursive copy including namespaces.

So now that I removed the xmlCopyNode and instead wrote:
xmlAddChild(parentNodePtr, newNodePtr);
everything is fine.

Could someone help me to understand why xmlCopyNode is not working in the
way I assumed?

By the way: The existing tree and the new subtree should have the same
namespace, so maybe there's a more clever way to do what I want?

Thanks in advance
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xml@gnome.org
http://mail.gnome.org/mailman/listinfo/xml

Reply via email to