+static int decode_SOLR_response(const char *content_buf, int content_len)
+{
+ xmlDocPtr doc = xmlParseMemory(content_buf, content_len);
+ int ret = 0;
+ xmlNodePtr ptr = 0;
+ Odr_int hits = 0;
+ Odr_int start = 0;
+
+ if (!doc)
+ {
+ ret = -1;
+ }
+ if (doc)
+ {
+ xmlNodePtr root = xmlDocGetRootElement(doc);
+ if (!root)
+ {
+ ret = -1;
+ }
+ else if (strcmp((const char *) root->name, "response"))
+ {
+ ret = -1;
+ }
+ else
+ {
+ /** look for result node */
+ for (ptr = root->children; ptr; ptr = ptr->next)
+ {
+ if (ptr->type == XML_ELEMENT_NODE &&
+ !strcmp((const char *) ptr->name, "result"))
+ break;
+ }
+ if (!ptr)
+ {
+ ret = -1;
+ }
+ }
+ }
+ if (ptr)
+ { /* got result node */
+ struct _xmlAttr *attr;
+ for (attr = ptr->properties; attr; attr = attr->next)
+ if (attr->children && attr->children->type == XML_TEXT_NODE)
+ {
+ if (!strcmp((const char *) attr->name, "numFound"))
+ {
+ hits = odr_atoi((const char *) attr->children->content);
+ }
+ else if (!strcmp((const char *) attr->name, "start"))
+ {
+ start = odr_atoi((const char *) attr->children->content);
+ }
+ }
+ printf("Number of hits: " ODR_INT_PRINTF "\n", hits);
+ }
+ if (ptr)
+ {
+ xmlNodePtr node;
+ int offset = 0;
+
+ for (node = ptr->children; node; node = node->next)
+ {
+ if (node->type == XML_ELEMENT_NODE)
+ {
+ xmlBufferPtr buf = xmlBufferCreate();
+ xmlNode *tmp = xmlCopyNode(node, 1);
+
+ printf(ODR_INT_PRINTF "\n", start + offset);
+
+ xmlNodeDump(buf, tmp->doc, tmp, 0, 0);
+
+ xmlFreeNode(tmp);
+
+ fwrite(buf->content, 1, buf->use, stdout);
+ xmlBufferFree(buf);
+ offset++;
+ printf("\n");
+ }
+ }
+ }
+ if (doc)
+ xmlFreeDoc(doc);
+ return ret;
+}
+