On Wed, Dec 28, 2011 at 09:56:53AM -0500, Piotr Sipika wrote:
> On 12/28/2011 02:19 AM, John J. Boyer wrote:
> > I need to delete some nodes from a parse tree. So I use xmlUnlinkNode
> > and then xmlFree. However, when I output the tree with xmlDumpDoc the
> > nodes are still there. What am I missing?
>
> It's difficult to say without seeing what you're doing exactly.
Agreed. But be sure to use xmlFreeNode() not xmlFree()
> Here's what works for me (sample program which deletes the first child
> element of the document root):
>
> xmlDocPtr pDoc = xmlParseFile(pczFileName);
> //error checking....
> xmlNodePtr pRoot = xmlDocGetRootElement(pDoc);
> //error checking...
>
> xmlNodePtr pNext = pRoot->children;
>
> int iDeleted = 0;
>
> while (pNext)
> {
> if (pNext->type == XML_ELEMENT_NODE && !iDeleted)
> {
> xmlNodePtr pDelNode = pNext;
>
> pNext = pNext->next;
>
> xmlUnlinkNode(pDelNode);
>
> xmlFree(pDelNode);
Ah, wrong, should be xmlFreeNode() or you are leaking
To avoid that mistake I added a small comment to xmlUnlinkNode
function documentation,
Daniel
--
Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/
[email protected] | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library http://libvirt.org/
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
[email protected]
http://mail.gnome.org/mailman/listinfo/xml