Deleting pieces: xml_delete

Previous: xml_free: Cleaning up afterwards ] [ Top: index ] [ Next: Children: xml_first and xml_last ]

Deleting a piece out of an XML structure is more than just freeing it; we have to close ranks before and after as well.
 
XMLAPI void xml_delete(XML * piece)
{
   ELEMENTLIST * list;
   if (!piece) return;
   if (piece->parent != NULL) {
      list = piece->parent->children;
      while (list != NULL && list->element != piece) list = list->next;
      if (list != NULL) {
         if (list->next != NULL) list->next->prev = list->prev;
         if (list->prev != NULL) list->prev->next = list->next;
      }
      if (list == piece->parent->children) piece->parent->children = list->next;
      if (list != NULL) FREE ((void *) list);
   }
   xml_free (piece);
}
Previous: xml_free: Cleaning up afterwards ] [ Top: index ] [ Next: Children: xml_first and xml_last ]


This code and documentation are released under the terms of the GNU license. They are additionally copyright (c) 2000, Vivtek. All rights reserved except those explicitly granted under the terms of the GNU license. This presentation was created using LPML.