Java Reference
In-Depth Information
{
processOption(buffer.toString(), value);
If an ending </choice> tag is found, then the list has ended, and we are done.
} else if (tag.getName().equalsIgnoreCase("/choice"))
{
break;
}
If it was a character that we found, and not a tag, then append it to the buffer vari-
able. The buffer will hold the state names that are between the <option> and
</option> tags.
}else
{
buffer.append((char) ch);
}
}
Once the loop completes, you will have all fifty states extracted.
Implementing the Advance Function
As previously mentioned, the advance function advances through several instances of
a tag, looking for the correct one. To do this the advance function enters a while loop
that will continue until the end of file is reached.
int ch;
while ((ch = parse.read()) != -1)
{
For each HTML tag encountered, see if the tag name matches the tag we are looking
for.
if (ch == 0)
{
if (parse.getTag().getName().equalsIgnoreCase(tag))
{
If the tag name matches, then decrease the count and return if the count has
reached zero. If the count has reached zero, then we have advanced to the correct location
and are done.
count--;
if (count <= 0)
return true;
}
If we fail to find the tag, then return false .
Search WWH ::




Custom Search