So my last blog post about my work on web services integration: GNOME web services integration: Introducing librest was quite some time ago. Apologies, things have been pretty busy with Moblin.
There are two traditional models for parsing XML, SAX and DOM based methods. These are both pretty heavyweight technologies but for the work i’m doing on web services I want something a bit lighter and a bit simpler to extract just the information I care about. Inspired by the Beautiful Soup HTML screen-scraping library I sought to build an API that lets you trivially find the content you are looking for.
Here is an example:
n = rest_xml_node_find (root, “photo”); while (n) { title = rest_xml_node_find (n, “title”); printf (“%s”, title->content); n = n->next; }
Fundamentally the libREST XML parsing strategy turns the XML into a tree of nodes, where a node can have siblings (accessed through a next pointer) or childen (stored in a hash of child tag name to node). This combined with a simple tree walking function (rest_xml_node_find) results in very minimalistic code for extracting just the content you care about.
You can find the source code for libREST in git.