Java Reference
In-Depth Information
Did you notice the difference? The biggest difference between the RSS 2.0 and RSS 1.0
formats that we need to contend with, is the placement of the <item> elements. RSS 2.0
places the <item> elements inside of the <channel> element. RSS 1.0 places the
<item> elements at the same level as the <channel> element.
Additionally, RSS 1.0 <item> elements do not contain a <pubDate> element. How-
ever, RSS 2.0 does include a <pubDate> element. The <pubDate> element contains
the date that the article or channel was last updated. RSS stores dates in the following for-
mat:
Sun, 8 Oct 2006 04:00:00 GMT
To work with RSS in Java, this date will need to be converted to a Java Date object.
Parsing RSS Files
In this section, we will develop a package of classes that can parse RSS data. This pack-
age will be used by the RSS recipes presented in this chapter. There will be only two classes
in this relatively simple package. These classes are:
• RSS
• RSSItem
The RSS class is the main entry point for this package. Using the RSS class, you can
parse RSS data. The RSSItem class holds individual RSS items, or articles, found when
parsing the RSS feed. In the next two sections, we will examine each of these classes.
This RSS parser is designed to work with either RSS 1.0 or RSS 2.0 feeds. The program
automatically adapts to each type of feed.
The RSS Class
The RSS class is the main class of the RSS parsing package and the class that you will
instruct to parse RSS . Additionally, the RSS class is used to navigate the RSS data that was
retrieved. The RSS class is shown below in Listing 12.3.
Listing 12.3: The RSS Class (RSS.java)
package com.heatonresearch.httprecipes.rss;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
Search WWH ::




Custom Search