gchar * gdata_feed_generate_xml(GDataFeed *feed) { GDataFeedPrivate *priv; xmlDocPtr doc; xmlNodePtr cur; xmlNodePtr root; xmlNsPtr ns_os, ns_gd, ns_gcal; xmlChar *xmlString; gint xml_buffer_size; GSList *list; g_return_val_if_fail(feed != NULL, NULL); g_return_val_if_fail(GDATA_IS_FEED(feed), NULL); priv = GDATA_FEED_GET_PRIVATE(feed); if (!priv->feedXML) { doc = xmlNewDoc ((xmlChar *)"1.0"); root = xmlNewDocNode (doc, NULL, (xmlChar *)"feed", NULL); xmlSetProp (root, (xmlChar *)"xmlns", (xmlChar *)"http://www.w3.org/2005/Atom"); ns_os = xmlNewNs (root, (xmlChar *)"http://a9.com/-/spec/opensearchrss/1.0/", (xmlChar *)"openSearch"); ns_gd = xmlNewNs (root, (xmlChar *)"http://schemas.google.com/g/2005", (xmlChar *)"gd"); ns_gcal = xmlNewNs (root, (xmlChar *)"http://schemas.google.com/gcal/2005", (xmlChar *)"gCal"); if (priv->id) { cur = xmlNewChild (root, NULL, (xmlChar *)"id", NULL); xmlNodeSetContent (cur, (xmlChar *)priv->id); } list = priv->categories; while (list) { cur = category_to_xmlnode (list->data); xmlAddChild (root, cur); list = g_slist_next (list); } list = priv->links; while (list) { cur = link_to_xmlnode (list->data); xmlAddChild (root, cur); list = g_slist_next (list); } list = priv->authors; while (list) { cur = author_to_xmlnode (list->data); xmlAddChild (root, cur); list = g_slist_next (list); } list = priv->entries; while (list) { cur = entry_to_xmlnode (list->data); xmlAddChild (root, cur); list = g_slist_next (list); } xmlDocDumpMemory (doc, &xmlString, &xml_buffer_size); priv->feedXML = g_strdup ((gchar *)xmlString); xmlFree (xmlString); xmlFreeDoc (doc); return priv->feedXML; } else { return priv->feedXML; } }
/** *gdata_entry_generate_xml: *@entry: A GDataEntry Object *Returns the xml content: **/ gchar * gdata_entry_generate_xml (GDataEntry *entry) { GDataEntryPrivate *priv; GSList *list; xmlChar *xmlString; xmlNsPtr ns; xmlNodePtr cur, cur_child, root; xmlDocPtr doc; gint xml_buffer_size; g_return_val_if_fail(entry !=NULL, NULL); g_return_val_if_fail(GDATA_IS_ENTRY (entry), NULL); priv = GDATA_ENTRY_GET_PRIVATE(entry); if (!(priv->entry_xml == NULL || priv->entry_needs_update == TRUE)) return priv->entry_xml; /* Construct DOM tree */ doc = xmlNewDoc ((xmlChar *)"1.0"); root = xmlNewDocNode (doc, NULL, (xmlChar *)"entry", NULL); xmlSetProp (root, (xmlChar *)"xmlns", (xmlChar *)"http://www.w3.org/2005/Atom"); ns = xmlNewNs (root, (xmlChar *)"http://schemas.google.com/g/2005", (xmlChar *)"gd"); xmlDocSetRootElement (doc, root); cur = root; list = priv->categories; while (list) { cur_child = category_to_xmlnode(list->data); xmlAddChild(root, cur_child); list = g_slist_next(list); } list = priv->authors; while (list) { cur_child = author_to_xmlnode(list->data); xmlAddChild(root, cur_child); list = g_slist_next(list); } list = priv->links; while (list) { cur_child = link_to_xmlnode(list->data); xmlAddChild(root, cur_child); list = g_slist_next(list); } if (priv->status) { cur_child = xmlNewChild(root, NULL, (xmlChar *)"eventStatus", NULL); xmlSetNs (cur_child, xmlNewNs (cur_child, NULL, (xmlChar *)"gd")); xmlSetProp (cur_child, (xmlChar *)"value", (xmlChar *)priv->status); } if (priv->start_time || priv->end_time || priv->reminder) { cur_child = xmlNewChild(root, NULL, (xmlChar *)"when", NULL); xmlSetNs (cur_child, xmlNewNs (cur_child, NULL, (xmlChar *)"gd")); xmlSetProp (cur_child, (xmlChar *)"startTime", (xmlChar *)priv->start_time); xmlSetProp (cur_child, (xmlChar *)"endTime", (xmlChar *)priv->end_time); if (priv->reminder) { cur = cur_child; cur_child = xmlNewChild(cur, NULL, (xmlChar *)"reminder", (xmlChar *)""); xmlSetNs (cur_child, xmlNewNs (cur_child, NULL, (xmlChar *)"gd")); xmlSetProp (cur_child->xmlChildrenNode, (xmlChar *)"minutes", (xmlChar *)priv->reminder); } } if (priv->location ) { cur_child = xmlNewChild(root, NULL, (xmlChar *)"where", NULL); xmlSetNs (cur_child, xmlNewNs (cur_child, NULL, (xmlChar *)"gd")); xmlSetProp (cur_child, (xmlChar *)"valueString", (xmlChar *)priv->location); } if (priv->content) { cur_child = xmlNewChild(root, NULL, (xmlChar *)"content", (xmlChar *)priv->content); xmlSetProp (cur_child, (xmlChar *)"type", (xmlChar *)"text"); } if (priv->title) { cur_child = xmlNewChild(root, NULL, (xmlChar *)"title", (xmlChar *)priv->title); xmlSetProp (cur_child, (xmlChar *)"type", (xmlChar *)"text"); } list = priv->email_addresses; while (list) { cur_child = email_address_to_xmlnode(list->data); xmlAddChild(root, cur_child); list = g_slist_next(list); } list = priv->im_addresses; while (list) { cur_child = im_address_to_xmlnode(list->data); xmlAddChild(root, cur_child); list = g_slist_next(list); } list = priv->organizations; while (list) { cur_child = organization_to_xmlnode(list->data); xmlAddChild(root, cur_child); list = g_slist_next(list); } list = priv->phone_numbers; while (list) { cur_child = phone_number_to_xmlnode(list->data); xmlAddChild(root, cur_child); list = g_slist_next(list); } list = priv->postal_addresses; while (list) { cur_child = postal_address_to_xmlnode(list->data); xmlAddChild(root, cur_child); list = g_slist_next(list); } /* if (priv->field_table) { g_hash_table_foreach (priv->field_table,(GHFunc) _build_hash_table_entries, &root); } */ xmlDocDumpMemory(doc, &xmlString, &xml_buffer_size); g_free (priv->entry_xml); priv->entry_xml = g_strdup((gchar *)xmlString); xmlFree(xmlString); xmlFreeDoc(doc); return priv->entry_xml; }