Java Reference
In-Depth Information
The above URL contains the following <link> tag:
<link rel="alternate"
type="application/rss+xml"
href="http://www.httprecipes.com/1/12/rss2.xml">
The href attribute of this tag tells us that we can find the RSS feed for the HTTP Reci-
pes site at the following URL:
http://www.httprecipes.com/1/12/rss2.xml
This recipe will show how to access the HTTP Recipes site, find the <link> tag for the
RSS Feed, and then download the RSS feed. This recipe is shown in Listing 12.6.
Listing 12.6: Find an RSS Feed (FindRSS.java)
package com.heatonresearch.httprecipes.ch12.recipe2;
import java.io.*;
import java.net.*;
import javax.xml.parsers.*;
import org.xml.sax.*;
import com.heatonresearch.httprecipes.html.*;
import com.heatonresearch.httprecipes.rss.*;
public class FindRSS
{
/**
* 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 processRSS(URL url) throws IOException,
SAXException, ParserConfigurationException
{
RSS rss = new RSS();
rss.load(url);
System.out.println(rss.toString());
}
Search WWH ::




Custom Search