Java Reference
In-Depth Information
/**
* The main method processes the command line arguments and
* 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/");
FindRSS load = new FindRSS();
load.process(url);
} catch (Exception e)
{
e.printStackTrace();
}
}
}
This recipe begins by opening a connection to the web site which we will scan for an
RSS URL. A ParseHTML object is setup to parse the HTML. The ParseHTML class was
discussed in Chapter 6.
String href = null;
InputStream is = url.openStream();
ParseHTML parse = new ParseHTML(is);
int ch;
The program will look through all of the tags in the document, ignoring the text between
HTML tags. Because this program is only looking for a <link> tag, the actual text does
not matter.
do
{
ch = parse.read();
if (ch == 0)
{
HTMLTag tag = parse.getTag();
Search WWH ::




Custom Search