Children: xml_first and xml_last

Previous: Deleting pieces: xml_delete ] [ Top: index ] [ Next: Siblings: xml_next and xml_prev ]

Finding the first child is, of course, very easy. The last is less so.

I've also tossed in a function xml_firstelem which is just like xml_first except that it doesn't see plain text elements.
 
XMLAPI XML * xml_first(XML * xml)
{
   if (xml == NULL) return NULL;
   if (xml->children == NULL) return NULL;
   return (xml->children->element);
}
XMLAPI XML * xml_firstelem(XML * xml)
{
   ELEMENTLIST *list;
   if (xml == NULL) return NULL;
   list = xml->children;
   while (list != NULL) {
      if (list->element->name != NULL) break;
      list = list->next;
   }
   if (list != NULL) return (list->element);
   return NULL;
}

XMLAPI XML * xml_last(XML *xml)
{
   if (xml == NULL) return NULL;
   if (xml->lastchild == NULL) return NULL;
   return (xml->lastchild->element);
}
XMLAPI XML * xml_lastelem(XML *xml)
{
   ELEMENTLIST *list;
   if (xml == NULL) return NULL;
   list = xml->lastchild;
   while (list != NULL) {
      if (list->element->name != NULL) break;
      list = list->prev;
   }
   if (list != NULL) return (list->element);
   return NULL;
}
Previous: Deleting pieces: xml_delete ] [ Top: index ] [ Next: Siblings: xml_next and xml_prev ]


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