diff options
Diffstat (limited to 'src/xml.c')
-rw-r--r-- | src/xml.c | 62 |
1 files changed, 61 insertions, 1 deletions
@@ -4,10 +4,18 @@ #include "xml.h" #include "logging.h" +struct xml_node { + void *data; + XML_StartElementHandler start; + XML_EndElementHandler end; + XML_CharacterDataHandler charhndl; + struct xml_node *parent; +}; + inline int xml_check_tag(const char *found, const char *expected) { - return strcmp(found, expected) != 0; + return strcmp(found, expected) == 0; } inline void @@ -53,6 +61,7 @@ xml_get_string_attr(XML_Parser p, const char **attr, const char *name, for (; attr[0] != NULL; attr += 2) { if (strcmp(attr[0], name) == 0) { *dest = strdup(attr[1]); + return; } } if (req) { @@ -60,3 +69,54 @@ xml_get_string_attr(XML_Parser p, const char **attr, const char *name, XML_StopParser(p, XML_FALSE); } } + +void +xml_node_push(XML_Parser p, void *data, + XML_StartElementHandler start, XML_EndElementHandler end, + XML_CharacterDataHandler charhndl) +{ + struct xml_node *n; + + n = malloc(sizeof(*n)); + if (n == NULL) { + return; + } + n->data = data; + n->start = start; + n->end = end; + n->charhndl = charhndl; + n->parent = (struct xml_node *) XML_GetUserData(p); + XML_SetUserData(p, n); + XML_SetStartElementHandler(p, n->start); + XML_SetEndElementHandler(p, n->end); + XML_SetCharacterDataHandler(p, n->charhndl); +} + +void * +xml_node_pop(XML_Parser p) +{ + struct xml_node *n; + void *data; + + n = (struct xml_node *) XML_GetUserData(p); + data = n->data; + XML_SetUserData(p, n->parent); + free(n); + + n = (struct xml_node *) XML_GetUserData(p); + XML_SetStartElementHandler(p, n->start); + XML_SetEndElementHandler(p, n->end); + XML_SetCharacterDataHandler(p, n->charhndl); + + return data; +} + +void * +xml_node_peek(XML_Parser p) +{ + struct xml_node *n; + + n = (struct xml_node *) XML_GetUserData(p); + + return n->data; +} |