Re: [xml] Copying node between documents


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:
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(
                 dest_doc, 1 /* with children */ );

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

Pawel Palucha

xml mailing list, project page
xml gnome org

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