int main (int argc, char **argv) { g_type_init (); RssParser *parser = rss_parser_new (); if (rss_parser_load_from_file (parser, "/tmp/atom.xml", NULL)) { RssDocument *doc = rss_parser_get_document (parser); GList *list, *tmp; gchar *title; list = rss_document_get_items (doc); for (tmp = list; tmp != NULL; tmp = tmp->next) { g_object_get (tmp->data, "title", &title, NULL); g_print ("%s\n", title); g_free (title); } g_list_free (list); g_object_unref (doc); } g_object_unref (parser); }
static gboolean on_rss_receive(gpointer data) { trg_response *response = (trg_response *) data; feed_update *update = (feed_update*) response->cb_data; TrgRssModel *model = update->model; TrgRssModelPrivate *priv = TRG_RSS_MODEL_GET_PRIVATE(model); if (response->status == CURLE_OK) { RssParser* parser = rss_parser_new(); GError *error = NULL; if (rss_parser_load_from_data(parser, response->raw, response->size, &error)) { RssDocument *doc = rss_parser_get_document(parser); GtkTreeIter iter; GList *list, *tmp; list = rss_document_get_items(doc); for (tmp = list; tmp != NULL; tmp = tmp->next) { RssItem *item = (RssItem*) tmp->data; const gchar *guid = rss_item_get_guid(item); if (g_hash_table_lookup(priv->table, guid) != (void*) 1) { gtk_list_store_append(GTK_LIST_STORE(model), &iter); gtk_list_store_set(GTK_LIST_STORE(model), &iter, RSSCOL_ID, guid, RSSCOL_TITLE, rss_item_get_title(item), RSSCOL_LINK, rss_item_get_link(item), RSSCOL_FEED, update->feed_id, RSSCOL_COOKIE, update->feed_cookie, RSSCOL_PUBDATE, rss_item_get_pub_date(item), -1); g_hash_table_insert(priv->table, g_strdup(guid), (void*) 1); } } g_list_free(list); g_object_unref(doc); g_object_unref(parser); } else { rss_parse_error perror; perror.error = error; perror.feed_id = update->feed_id; g_signal_emit(model, signals[SIGNAL_PARSE_ERROR], 0, &perror); g_message("parse error: %s", error->message); g_error_free(error); } } else { rss_get_error get_error; get_error.error_code = response->status; get_error.feed_id = update->feed_id; g_signal_emit(model, signals[SIGNAL_GET_ERROR], 0, &get_error); } trg_response_free(response); feed_update_free(update); return FALSE; }