Covering some RSS basics
Before I jump into the details of downloading an RSS feed and process it with an Android-based RSS reader, let's take a quick look at the need for RSS, where RSS is used, and how it is structured.
The multitude of information dissemination tools ranges from free radio, public and cable television, printed media, and even that moderately disruptive technology called the Internet with its abundance of Web sites and e-mail subscriptions. The problem with this vast array of choices is that it is often difficult to find the information of real interest and value amongst the noise and volume of data. Thankfully, RSS can assist with this challenge.
RSS stands for "Really Simple Syndication". RSS is an XML data format used by publishers of content to distribute information that is categorized and is suitable for both human and machine consumption. RSS feeds are typically processed and presented to users in a friendly human-readable format such as a news reader including the application built in this tutorial. RSS feeds are also consumed by computers to generate subsequent, aggregated information sources. An example of a machine-consumed RSS feed might be a listing of available rental properties that is retrieved periodically and fed into a travel agent's local reservation system.
RSS is typically mentioned when discussing news stories, however the format can be used to organize and publish many types of information beyond news. For example, many Web sites publish an RSS feed of available pod-casts to distribute audio and video content. Handango.com, a popular online merchant of mobile software and content, supplies RSS feeds of new and popular software titles, categorized by mobile platform. For example, there is a feed for Windows® Mobile, Blackberry, Palm and others. Before too long, there will hopefully be a feed for Android applications as well!
The format of RSS is XML data, meaning the data itself contains descriptive elements such that it is self-contained. The XML layout over the past few years has undergone some changes as the industry has normalized a bit. The most recent and generally accepted version is 2.0. RSS 2.0 is a relatively simple XML layout that is readily parsed by computer programs. In this tutorial, the sample application demonstrates the parsing of an RSS feed taken from the Web site of IBM developerWorks.
Enough discussion in the abstract about which version is most popular, let's examine the specification for RSS 2.0. The RSS 2.0 format includes only a few tags. You have the obligatory <?xml> tag, which every XML document requires. The first real tag is the <rss> tag, which includes the version as an attribute. Following the <rss> tag is one or more channels where each channel includes the elements shown in Listing 1.
Listing 1. Channels and elements in RSS 2.0
<channel> <title/> <link/> <description/> <pubDate /> <language/> <copyright/> <image> <title /> <url /> <link /> </image> + <item /> </channel> </rss>
Each channel may have one or more items. Each item has the structure shown in Listing 2.
Listing 2. Item structure
<item> <title /> <description /> <link /> <category /> <pubDate /> </item>
The consumer of an RSS feed determines how to display the data. Typically an RSS reader displays some title information regarding the available channels, including the publication date (found in the pubDate element). Remember, RSS is about publishing relevant, timely data so the publication date should not be ignored. Figure 1 demonstrates this tutorial's sample application in action displaying an RSS feed. Figure 1 displays the title of the RSS feed, the publication date and displays the items in a List format. Later in this tutorial, I discuss the mechanics of getting the parsed RSS feed into the Android user interface.
Figure 1. Android RSS reader in action
The elements of the item tag of an RSS feed describe each contained item of the feed. For example, in this tutorial, you are working with an RSS feed that contains a list of popular tutorials from the developerWorks site at IBM. Each entry in the feed includes enough information to give the consumer a feel for what the topic is about and how to learn more. There are three levels of information, each of increasing verbosity and detail. In addition, each entry contains a publication date and category information. The title of the item gives a brief feel for what the topic is, for example:
<title><![CDATA[Develop Android applications with Eclipse]]></title>.
This tells you enough about this item to peak your interest if you care to learn about using Eclipse for Android development. If the consumer (that is, the person using the application) wants to learn more, there is more information to provide, namely the description from Listing 3.
Listing 3. The description
<description><![CDATA[Android is Google's oft-discussed mobile, wireless, computer, and communications platform. You can take advantage of the powerful Eclipse environment to build Android applications using the Android Eclipse plug-in. This tutorial introduces Android application development with the Eclipse plug-in, otherwise known as Android Development Tools. The tutorial provides an introduction to Android development with a quick introduction to the platform, a tour of Android Development Tools, and includes the construction of two example applications. ]]></description>
Note the use of the CDATA XML technique. CDATA is used when the XML feed might contain mark-up elements which can interfere with the containing XML tags. One of the side effects of CDATA is that the data is taken as is, so you might need additional formatting to occur on the text for it to display properly in the target user interface. You'll see an example of this in the sample application, introduced later in this tutorial.
Finally, if consumers are very interested in this topic, a link is provided where they can find even more information on the specific topic:
<link> <![CDATA[http://www.ibm.com/developerworks/edu/os-dw-os-eclipse-android.html?ca=drs-]]> </link>
This tutorial does not dive into any special handling of the category as all of the categories in this particular RSS feed are the same. The publication date is displayed as a best practice technique.
Now that you know a little bit about RSS and where it is used, let's take a high-level look at the RSS reader application architecture.