Java Reference
In-Depth Information
Recipes
This chapter includes two recipes. These recipes demonstrate how to parse RSS feeds.
Specifically, you will see how to perform the following techniques:
• Parse an RSS Feed
• Find an RSS Feed from a Link Tag
These recipes will show you how a bot can be adapted to work with RSS feeds. The first
recipe demonstrates how to display an RSS feed.
Recipe #12.1: Display an RSS Feed
This recipe demonstrates how to open an RSS feed and parse it. The recipe will work with
either an RSS 1.0 or RSS 2.0 feed. It relies on the RSS parser, which was constructed earlier
in this chapter. This recipe is shown in Listing 12.5.
Listing 12.5: Display an RSS Feed (LoadRSS.java)
package com.heatonresearch.httprecipes.ch12.recipe1;
import java.io.*;
import java.net.*;
import javax.xml.parsers.*;
import org.xml.sax.*;
import com.heatonresearch.httprecipes.rss.*;
public class LoadRSS
{
/**
* Display an RSS feed.
* @param url The URL of the RSS feed.
* @throws IOException Thrown if an IO exception occurs.
* @throws SAXException Thrown if an XML parse exception occurs.
* @throws ParserConfigurationException Thrown if there is
* an error setting up the parser.
*/
public void process(URL url) throws IOException, SAXException,
ParserConfigurationException
{
RSS rss = new RSS();
rss.load(url);
System.out.println(rss.toString());
}
/**
* The main method processes the command line arguments and
Search WWH ::




Custom Search