xml_create: Creating an empty element

Previous: Working with attributes: xml_set and xml_attrval ] [ Top: index ] [ Next: xml_createtext: a shortcut for plain text ]

Creation of an element is nothing more than allocating the space, then allocating space for a copy of the name and copying it.

For extra credit, determine how omitting the initialization of ret->parent would screw up xml_read later on. But only sometimes. That stupid omission cost me a rather horrible evening in July of 2000.
 
XMLAPI XML * xml_create (const char * name)
{
   XML * ret;

   ret = (XML *) MALLOC (sizeof (struct _element));
   ret->name = strdup (name);
   ret->attrs = NULL;
   ret->children = NULL;
   ret->parent = NULL;

   return (ret);
}
Previous: Working with attributes: xml_set and xml_attrval ] [ Top: index ] [ Next: xml_createtext: a shortcut for plain text ]


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.