XML parsing

Utility functions for doing simple XML parsing. More...

Data Structures

struct  _GGZXMLElement
 Object representing a single XML element. More...

Typedefs

typedef _GGZXMLElement GGZXMLElement
 Object representing a single XML element.

Functions

GGZXMLElementggz_xmlelement_new (const char *tag, const char *const *attrs, void(*process)(void *, GGZXMLElement *), void(*free)(GGZXMLElement *))
 Create a new GGZXMLElement element.
void ggz_xmlelement_init (GGZXMLElement *element, const char *tag, const char *const *attrs, void(*process)(void *, GGZXMLElement *), void(*free)(GGZXMLElement *))
 Initialize a GGZXMLElement.
void ggz_xmlelement_set_data (GGZXMLElement *element, void *data)
 Set ancillary data on a GGZXMLElement object.
const char * ggz_xmlelement_get_tag (GGZXMLElement *element)
 Get an XML element's name.
const char * ggz_xmlelement_get_attr (GGZXMLElement *element, const char *attr)
 Get the value of an attribute on XML element.
void * ggz_xmlelement_get_data (GGZXMLElement *element)
 Get the user-supplied data associated with an XML element.
char * ggz_xmlelement_get_text (GGZXMLElement *element)
 Get an XML element's content text.
void ggz_xmlelement_add_text (GGZXMLElement *element, const char *text, int len)
 Append a string to the element's content text.
void ggz_xmlelement_free (GGZXMLElement *element)
 Free the memory associated with an XML element.

Detailed Description

Utility functions for doing simple XML parsing.

These can be used with streaming XML parsers, and don't have the overhead of a full DOM tree. GGZXMLElement represents a single element, along with its attributes and text data.

Note:
This does not parse your XML. It is simply for use to store the data as you are parsing.

Function Documentation

GGZXMLElement* ggz_xmlelement_new ( const char *  tag,
const char *const *  attrs,
void(*)(void *, GGZXMLElement *)  process,
void(*)(GGZXMLElement *)  free 
)

Create a new GGZXMLElement element.

Parameters:
tag The name of the XML element (tag)
attrs NULL terminated array of attributes/values. These must alternate: attribute1, value1, attribute2, value2, etc.
process User-defined function for processing XML elements
free User-defined function for deallocating GGZXMLElement objects. If provided, this will be invoked by ggz_xmlelement_free(), and in addition to any user-defined processing should call ggz_free() the element itself.
Returns:
Pointer to a newly allocated GGZXMLElement object

void ggz_xmlelement_init ( GGZXMLElement element,
const char *  tag,
const char *const *  attrs,
void(*)(void *, GGZXMLElement *)  process,
void(*)(GGZXMLElement *)  free 
)

Initialize a GGZXMLElement.

Parameters:
element Pointer to a GGZXMLElement to initialize
tag The name of the XML element (tag)
attrs NULL terminated array of attributes/values. These must alternate: attribute1, value1, attribute2, value2, etc.
process User-defined function for processing XML elements
free User-defined function for deallocating GGZXMLElement objects. If provided, this will be invoked by ggz_xmlelement_free(), and in addition to any user-defined processing should call ggz_free() the element itself.
Returns:
Pointer to a newly allocated GGZXMLElement object

void ggz_xmlelement_set_data ( GGZXMLElement element,
void *  data 
)

Set ancillary data on a GGZXMLElement object.

Associate some extra data with an XML element.

Parameters:
element Pointer to an XML element
data Pointer to user-supplied data
Returns:
The element's name

const char* ggz_xmlelement_get_tag ( GGZXMLElement element  ) 

Get an XML element's name.

Parameters:
element Pointer to an XML element
Returns:
The element's name

const char* ggz_xmlelement_get_attr ( GGZXMLElement element,
const char *  attr 
)

Get the value of an attribute on XML element.

Parameters:
element Pointer to an XML element
attr An attribute name
Returns:
The value of the attribute, or NULL is there is no such attribute present

void* ggz_xmlelement_get_data ( GGZXMLElement element  ) 

Get the user-supplied data associated with an XML element.

Parameters:
element Pointer to an XML element
Returns:
Pointer to the user-supplied data

char* ggz_xmlelement_get_text ( GGZXMLElement element  ) 

Get an XML element's content text.

Parameters:
element Pointer to an XML element
Returns:
The text content of the element

void ggz_xmlelement_add_text ( GGZXMLElement element,
const char *  text,
int  len 
)

Append a string to the element's content text.

Parameters:
element Pointer to an XML element
text String to append
len The string's length, in bytes

void ggz_xmlelement_free ( GGZXMLElement element  ) 

Free the memory associated with an XML element.

Parameters:
element Pointer to an XML element


Generated on Fri Nov 30 14:58:03 2007 for LibGGZ by  doxygen 1.5.1