Re: [xml] Copying node between documents



Pawel,

Try removing the xmlUnlinkNode(node) statement. You are unlinking a
"copy" of the node list not the original. Also do you really need to
unlink the node list in the original document.


On Tue, 2004-11-09 at 18:34, Paweł Pałucha wrote:
Hi,
I want to find a node in one document with xpath query and then to add 
set of nodes from another document as its children. I can't do it 
without loosing some memory (or generating sigsegv). I tried something 
like this:

xmlXPathContextPtr dest_ctx, src_ctx;
xmlXPathObjectPtr insert_point, src_set;
xmlNodePtr node;
int i;

dest_ctx = xmlXPathNewContext(dest_doc);
insert_point = xmlXPathEvalExpression("...", dest_doc);

src_ctx = xmlXPathNewContext(src_doc);
src_set = xmlXPathEvalExpression("...", src_ctx);

for (i = 0; i < src_set->nodesetval->nodeNr; i++) {
      xmlNodePtr node = xmlDocCopyNode(
              xpath_obj->nodesetval->nodeTab[i],
                 dest_doc, 1 /* with children */ );
      xmlUnlinkNode(node);
      xmlAddChild(insert_point->nodesetval->nodeNr[0],
              node);
}


Valgrind show huge memory leaks, but adding xmlFreeNode(node) makes 
program crush. Where and how should I free memory? I call xmlFreeDoc() 
and xmlCleanupParser()...

Thanks
Pawel Palucha

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





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