Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#126 Deleting a TiXmlNode should update its parent and siblings

open
nobody
None
5
2012-01-04
2012-01-04
Anonymous
No

The destructor method for TiXmlNode removes its children but does not update its parent or sibling pointers. Evidently the TiXmlNode::RemoveChild method handles this correctly. Since a 'parent' pointer is available for each node, it should be straightforward to update the parent and siblings on destruction (it seems more logical to move the linked list modifications in RemoveChild into the TiXmlNode destructor, then the final 'delete removeThis' in the RemoveChild method will handle the updates.)

Unless there's something I'm missing, I would do the following (this is untested btw):

1) Remove this code from TiXmlNode ::RemoveChild:
//
if ( removeThis->next )
removeThis->next->prev = removeThis->prev;
else
lastChild = removeThis->prev;

if ( removeThis->prev )
removeThis->prev->next = removeThis->next;
else
firstChild = removeThis->next;
//

2) Add this code to the end of TiXmlNode::~TiXmlNode:

if (next )
next->prev = prev;
else if (parent)
parent->lastChild = prev;

if (prev)
prev->next = next;
else if (parent)
parent->firstChild = next;

Discussion

  • kunal
    kunal
    2012-07-22

    I am interested in fixing this bug. Please tell me how to proceed on the same.