Java Reference
In-Depth Information
Listing 6.5: Parse an HTML List (ParseList.java)
package com.heatonresearch.httprecipes.ch6.recipe2;
import java.io.*;
import java.net.*;
import com.heatonresearch.httprecipes.html.*;
public class ParseList
{
/**
* Advance to the specified HTML tag.
* @param parse The HTML parse object to use.
* @param tag The HTML tag.
* @param count How many tags like this to find.
* @return True if found, false otherwise.
* @throws IOException If an exception occurs while reading.
*/
private boolean advance(ParseHTML parse, String tag, int count)
throws IOException
{
int ch;
while ((ch = parse.read()) != -1)
{
if (ch == 0)
{
if (parse.getTag().getName().equalsIgnoreCase(tag))
{
count--;
if (count <= 0)
return true;
}
}
}
return false;
}
/*
* Handle each list item, as it is found.
*/
private void processItem(String item)
{
System.out.println(item);
}
Search WWH ::




Custom Search