+void parse_statuses(xmlDocPtr doc, xmlNodePtr current)
+{
+ xmlChar *text = NULL;
+ xmlChar *user = NULL;
+ xmlNodePtr userinfo;
+
+ current = current->xmlChildrenNode;
+ while (current != NULL) {
+ if (current->type == XML_ELEMENT_NODE) {
+ if (!xmlStrcmp(current->name, (const xmlChar *)"text"))
+ text = xmlNodeListGetString(doc, current->xmlChildrenNode, 1);
+ if (!xmlStrcmp(current->name, (const xmlChar *)"user")) {
+ userinfo = current->xmlChildrenNode;
+ while (userinfo != NULL) {
+ if ((!xmlStrcmp(userinfo->name, (const xmlChar *)"screen_name"))) {
+ if (user)
+ xmlFree(user);
+ user = xmlNodeListGetString(doc, userinfo->xmlChildrenNode, 1);
+ }
+ userinfo = userinfo->next;
+ }
+ }
+ if (user && text) {
+ printf("[%s] %s\n", user, text);
+ xmlFree(user);
+ xmlFree(text);
+ user = NULL;
+ text = NULL;
+ }
+ }
+ current = current->next;
+ }
+
+ return;
+}
+
+static void parse_timeline(char *document)
+{
+ xmlDocPtr doc;
+ xmlNodePtr current;
+ doc = xmlReadMemory(document, strlen(document), "timeline.xml", NULL, XML_PARSE_NOERROR);
+
+ if (doc == NULL)
+ return;
+
+ current = xmlDocGetRootElement(doc);
+ if (current == NULL) {
+ fprintf(stderr, "empty document\n");
+ xmlFreeDoc(doc);
+ return;
+ }
+
+ if (xmlStrcmp(current->name, (const xmlChar *) "statuses")) {
+ fprintf(stderr, "unexpected document type\n");
+ xmlFreeDoc(doc);
+ return;
+ }
+
+ current = current->xmlChildrenNode;
+ while (current != NULL) {
+ if ((!xmlStrcmp(current->name, (const xmlChar *)"status")))
+ parse_statuses(doc, current);
+ current = current->next;
+ }
+ xmlFreeDoc(doc);
+
+ return;
+}
+