예제 #1
0
int main ()
{
	GError *error;
	GList *iter;
	GList *list;
	GrssFeedChannel *feed;
	GrssFeedItem *item;
	GrssFeedsPublisher *publisher;

	g_type_init ();

	list = NULL;

	feed = grss_feed_channel_new ();
	grss_feed_channel_set_title (feed, "Test Feed");
	grss_feed_channel_set_homepage (feed, "http://example.com");
	grss_feed_channel_set_description (feed, "A test feed");
	grss_feed_channel_set_publish_time (feed, time (NULL));

	item = grss_feed_item_new (feed);
	grss_feed_item_set_title (item, "A big news!");
	grss_feed_item_set_description (item, "Something incredible happening!");
	grss_feed_item_set_source (item, "http://slashdot.org");
	list = g_list_prepend (list, item);

	item = grss_feed_item_new (feed);
	grss_feed_item_set_title (item, "libgrss released");
	grss_feed_item_set_description (item, "A new version of the best Glib-based RSS management library has been released");
	grss_feed_item_set_source (item, "http://live.gnome.org/Libgrss");
	list = g_list_prepend (list, item);

	item = grss_feed_item_new (feed);
	grss_feed_item_set_title (item, "A new commit in libgrss");
	grss_feed_item_set_description (item, "Some commit happens on libgrss git repository");
	grss_feed_item_set_source (item, "http://git.gnome.org/browse/libgrss");
	list = g_list_prepend (list, item);

	error = NULL;
	publisher = grss_feeds_publisher_new ();
	if (grss_feeds_publisher_publish_file (publisher, feed, list, "file:///tmp/test.xml", &error) == FALSE) {
		printf ("Unable to write file: %s\n", error->message);
		g_error_free (error);
	}

	for (iter = list; iter; iter = g_list_next (iter))
		g_object_unref (iter->data);

	g_list_free (list);
	g_object_unref (feed);
	exit (0);
}
예제 #2
0
static void
parse_channel (FeedRssHandler *parser, GrssFeedChannel *feed, xmlDocPtr doc, xmlNodePtr cur) {
	gchar *tmp;
	time_t t;

	g_assert (NULL != cur);
	cur = cur->xmlChildrenNode;

	while (cur) {
		if (cur->type != XML_ELEMENT_NODE || cur->name == NULL) {
			cur = cur->next;
			continue;
		}

		/* check namespace of this tag */
		if (cur->ns) {
			if (ns_handler_channel (parser->priv->handler, feed, cur)) {
				cur = cur->next;
				continue;
			}
		}

		if (!xmlStrcmp (cur->name, BAD_CAST"copyright")) {
 			tmp = (gchar*) xmlNodeListGetString (doc, cur->xmlChildrenNode, 1);
			if (tmp) {
				grss_feed_channel_set_copyright (feed, tmp);
				g_free (tmp);
			}
		}
		else if (!xmlStrcmp (cur->name, BAD_CAST"webMaster") || !xmlStrcmp (cur->name, BAD_CAST"publisher")) {
 			tmp = (gchar*) xmlNodeListGetString (doc, cur->xmlChildrenNode, 1);
			if (tmp) {
				grss_feed_channel_set_webmaster (feed, tmp);
				g_free (tmp);
			}
		}
		else if (!xmlStrcmp (cur->name, BAD_CAST"language")) {
 			tmp = (gchar*) xmlNodeListGetString (doc, cur->xmlChildrenNode, 1);
			if (tmp) {
				grss_feed_channel_set_language (feed, tmp);
				g_free (tmp);
			}
		}
		else if (!xmlStrcmp (cur->name, BAD_CAST"managingEditor")) {
 			tmp = (gchar*) xmlNodeListGetString (doc, cur->xmlChildrenNode, 1);
			if (tmp) {
				grss_feed_channel_set_editor (feed, tmp);
				g_free (tmp);
			}
		}
		else if (!xmlStrcmp (cur->name, BAD_CAST"lastBuildDate")) {
 			tmp = (gchar*) xmlNodeListGetString (doc, cur->xmlChildrenNode, 1);
			if (tmp) {
				t = date_parse_RFC822 (tmp);
				grss_feed_channel_set_update_time (feed, t);
				g_free (tmp);
			}
		}
		else if (!xmlStrcmp (cur->name, BAD_CAST"generator")) {
 			tmp = (gchar*) xmlNodeListGetString (doc, cur->xmlChildrenNode, 1);
			if (tmp) {
				grss_feed_channel_set_generator (feed, tmp);
				g_free (tmp);
			}
		}
		else if (!xmlStrcmp (cur->name, BAD_CAST"pubDate")) {
 			if (NULL != (tmp = (gchar*) xmlNodeListGetString (doc, cur->xmlChildrenNode, 1))) {
				t = date_parse_RFC822 (tmp);
				grss_feed_channel_set_publish_time (feed, t);
				g_free (tmp);
			}
		}
		else if (!xmlStrcmp (cur->name, BAD_CAST"ttl")) {
 			if (NULL != (tmp = (gchar*) xmlNodeListGetString (doc, cur->xmlChildrenNode, TRUE))) {
				grss_feed_channel_set_update_interval (feed, atoi (tmp));
				g_free (tmp);
			}
		}
		else if (!xmlStrcmp (cur->name, BAD_CAST"title")) {
 			if (NULL != (tmp = unhtmlize ((gchar*) xmlNodeListGetString (doc, cur->xmlChildrenNode, TRUE)))) {
				grss_feed_channel_set_title (feed, tmp);
				g_free (tmp);
			}
		}
		/*
			<alink> has been found at least in Xinhua News Agency RSS feeds
		*/
		else if (!xmlStrcmp (cur->name, BAD_CAST"link") || !xmlStrcmp (cur->name, BAD_CAST"alink")) {
 			if (NULL != (tmp = unhtmlize ((gchar*) xmlNodeListGetString (doc, cur->xmlChildrenNode, TRUE)))) {
				grss_feed_channel_set_homepage (feed, tmp);
				g_free (tmp);
			}
		}
		else if (!xmlStrcmp (cur->name, BAD_CAST"description")) {
			tmp = (gchar*) xmlNodeListGetString (doc, cur->xmlChildrenNode, TRUE);
			if (tmp) {
				grss_feed_channel_set_description (feed, tmp);
				g_free (tmp);
			}
		}
		else if (!xmlStrcmp (cur->name, BAD_CAST"cloud")) {
 			parse_rss_cloud (feed, cur);
		}

		cur = cur->next;
	}
}