summaryrefslogtreecommitdiff
path: root/rest/rest-xml-parser.c
diff options
context:
space:
mode:
authorRob Bradford <rob@o-hand.com>2008-09-01 11:09:28 +0100
committerRob Bradford <rob@o-hand.com>2008-09-01 11:09:28 +0100
commit73bd0fc5497c4503639be9dec55eda3fbcd9296e (patch)
treefaf66780ae580c8556e6a7572852d7d3d182174e /rest/rest-xml-parser.c
parent4cd45fd6214907831e6864eb18691f885341c1f8 (diff)
downloadlibrest-73bd0fc5497c4503639be9dec55eda3fbcd9296e.tar.gz
Add _find and _get_attrs to the parser API
Diffstat (limited to 'rest/rest-xml-parser.c')
-rw-r--r--rest/rest-xml-parser.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/rest/rest-xml-parser.c b/rest/rest-xml-parser.c
index b8c94c1..b3f2f61 100644
--- a/rest/rest-xml-parser.c
+++ b/rest/rest-xml-parser.c
@@ -109,6 +109,44 @@ rest_xml_node_free (RestXmlNode *node)
g_slice_free (RestXmlNode, node);
}
+const gchar *
+rest_xml_node_get_attr (RestXmlNode *node,
+ const gchar *attr_name)
+{
+ return g_hash_table_lookup (node->attrs, attr_name);
+}
+
+RestXmlNode *
+rest_xml_node_find (RestXmlNode *start,
+ const gchar *tag)
+{
+ RestXmlNode *node;
+ RestXmlNode *tmp;
+ GQueue *stack;
+ GList *children, *l;
+
+ stack = g_queue_new ();
+ g_queue_push_head (stack, start);
+
+ while ((node = g_queue_pop_head (stack)) != NULL)
+ {
+ if ((tmp = g_hash_table_lookup (node->children, tag)) != NULL)
+ {
+ g_queue_free (stack);
+ return tmp;
+ }
+
+ children = g_hash_table_get_values (node->children);
+ for (l = children; l; l = l->next)
+ {
+ g_queue_push_head (stack, l->data);
+ }
+ g_list_free (children);
+ }
+
+ return NULL;
+}
+
RestXmlParser *
rest_xml_parser_new (void)
{