[xml] Can i use xmlUnlinkNode + xmlFreeNode to free a xmlNode in xmlNodeSetPtr of xmlXPathObjectPtr?


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];
                    /* xpathObj->nodesetval->nodeTab[i] should be set NULL,
                       otherwise xmlXPathFreeNodeSet (called by
                       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.

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