]> saetta.ns0.it Git - libgapp/commitdiff
libxml parsing retrieved service document.
authorAndrea Zagli <azagli@libero.it>
Sun, 30 Dec 2012 17:45:08 +0000 (18:45 +0100)
committerAndrea Zagli <azagli@libero.it>
Sun, 30 Dec 2012 17:45:08 +0000 (18:45 +0100)
src/service.c
tests/service.c

index 8a0187a3aa20ceffa58999cd981b938aa1c63cf5..80a1d0d5f1dad5c8c8c85177d3c767231ff9b98f 100644 (file)
@@ -140,10 +140,26 @@ GappService
        if (SOUP_STATUS_IS_SUCCESSFUL (msg->status_code))
                {
                        g_message ("Message GET: success (%d).", msg->status_code);
+
+                       priv->xdoc = xmlParseDoc ((const xmlChar *)msg->response_body->data);
+                       if (priv->xdoc == NULL)
+                               {
+                                       g_warning ("Unable to parse xml.");
+                                       g_object_unref (service);
+                                       service = NULL;
+                               }
+                       else
+                               {
+                                       priv->xroot = xmlDocGetRootElement (priv->xdoc);
+                               }
                }
        else
                {
-                       g_message ("Message GET: error (%d).", msg->status_code);
+                       g_warning ("Message GET: error (%d): %s.",
+                                  msg->status_code,
+                                  msg->reason_phrase);
+                       g_object_unref (service);
+                       service = NULL;
                }
 
        return service;
@@ -158,21 +174,9 @@ GappService
 xmlDoc
 *gapp_service_get_xml_doc (GappService *service)
 {
-       xmlNode *xnode;
-       GList *lst;
-
        GappServicePrivate *priv = GAPP_SERVICE_GET_PRIVATE (service);
 
-       xmlDoc *xdoc = xmlNewDoc ((const xmlChar *)"1.0");
-       xmlNode *xroot = xmlNewNode (NULL, (const xmlChar *)"feed");
-
-       /* adding root element */
-       if (xroot == NULL) return NULL;
-
-       xmlNewNs (xroot, (const xmlChar *)"http://www.w3.org/2005/Atom", NULL);
-       xmlDocSetRootElement (xdoc, xroot);
-
-       return xdoc;
+       return priv->xdoc;
 }
 
 /**
index 3b0899d1167071970d42c5934fc18d77a5322f2d..9a548a90d5eb19041eb17ca9e43864f05ada9bc4 100644 (file)
@@ -8,6 +8,10 @@ main (int argc, char *argv[])
        GappService *service;
 
        service = gapp_service_new (argv[1]);
+       if (service != NULL)
+               {
+                       gapp_service_save_file (service, "service_test.xml");
+               }
 
        return 0;
 }