Java Reference
In-Depth Information
* then calls process to display the feed.
*
* @param args Holds the RSS feed to download.
*/
public static void main(String args[])
{
try
{
URL url;
if (args.length != 0)
url = new URL(args[0]);
else
url = new URL("http://www.httprecipes.com/1/12/rss1.xml");
LoadRSS load = new LoadRSS();
load.process(url);
} catch (Exception e)
{
e.printStackTrace();
}
}
}
This recipe is very simple. It begins by creating a new RSS object. The RSS class was
constructed earlier in this chapter.
RSS rss = new RSS();
Next, the load method is called to load a RSS feed.
rss.load(url);
Finally, the RSS feed is displayed by calling the RSS object's toString function.
System.out.println(rss.toString());
If you need to access the RSS items directly, you can easily use the getItems function
to obtain a list of RSSItem objects.
Recipe #12.2: Find an RSS Feed
Many web sites contain a special <link> tag that shows you where the RSS feed for
that site resides. By parsing for this <link> tag, you can easily obtain the RSS feed for a
web site. The HTTP Recipes site contains such a tag. If you examine the source at the follow-
ing URL, you will see this tag.
http://www.httprecipes.com/
Search WWH ::




Custom Search