Re: [xml] Can i use xmlUnlinkNode + xmlFreeNode to free a xmlNode in xmlNodeSetPtr of xmlXPathObjectPtr?
- From: Daniel Veillard <veillard redhat com>
- To: åæ <yuantao cn gmail com>
- Cc: xml gnome org
- Subject: Re: [xml] Can i use xmlUnlinkNode + xmlFreeNode to free a xmlNode in xmlNodeSetPtr of xmlXPathObjectPtr?
- Date: Fri, 17 Apr 2009 10:56:12 +0200
On Fri, Apr 17, 2009 at 03:54:18PM +0800, åæ wrote:
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?
xmlXPathFreeObject free only the object not any of the node which may
be pointed, with the only exception of namespace nodes where libxml2 and
XPath model didn't match.
It seems that xmlXPathFreeObject() call xmlXPathFreeNodeSet() to free
the node, this different with xmlFreeNode().
What's the correct way in this case.
You need to unlink and free the node, and set the given entry to NULL
in the XPath nodeset.
Daniel
--
Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/
daniel veillard com | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library http://libvirt.org/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]