Hi,

I just sustaining some codes used libxml.
The basic code logic is like this:

            xpathObj = xmlXPathEvalExpression((xmlChar*)xpathExpr, xpathCtx);
            for (i=0; i<xpathObj->nodesetval->nodeNr; i++) {
                xmlNodePtr newNode =
xmlAddPrevSibling(xpathObj->nodesetval->nodeTab[i], dataNode);
                if (newNode) {
                    newNode = xpathObj->nodesetval->nodeTab[i];
                    xmlUnlinkNode(newNode);
                    xmlFreeNode(newNode);
                    /* xpathObj->nodesetval->nodeTab[i] should be set NULL,
                       otherwise xmlXPathFreeNodeSet (called by
xmlXPathFreeObject)
                       will access a unkonw memory */
                    xpathObj->nodesetval->nodeTab[i] = NULL;
                }
            }
            ,,,,,,,,,,,,
            xmlXPathFreeObject(xpathObj );


you can suppose it's a update action: add the new node, and remove the old node.

I just wonder should i call xmlFreeNode to free old Node?
Or just unlink it, then xmlXPathFreeObject free it?

It seems that xmlXPathFreeObject() call xmlXPathFreeNodeSet() to free
the node, this different with xmlFreeNode().
What's the correct way in this case.

Thanks very much.
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
[email protected]
http://mail.gnome.org/mailman/listinfo/xml

Reply via email to