Re: [xml] Problem using xmlUnlinkNode
- From: Daniel Veillard <veillard redhat com>
- To: Piotr Sipika <piotreks optonline net>
- Cc: xml gnome org
- Subject: Re: [xml] Problem using xmlUnlinkNode
- Date: Thu, 26 Jan 2012 21:16:31 +0800
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/
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]