Java Reference
In-Depth Information
if (source.peek() == '<')
{
parseTag();
return 0;
If an ampersand is found, then a special character will follow. Calling
parseSpecialCharacter
will handle the special HTML character.
} else if (source.peek() == '&')
{
return parseSpecialCharacter();
Finally, if it is a regular HTML character, simply return that character.
} else
{
return (source.read());
}
Encapsulating HTML Tags
When you call the
getTag
function of the HTML parse class, you are given an
HTMLTag
object. This object completely encapsulates the HTML tag that was just parsed.
The
HTMLTag
class is shown in Listing 6.3.
Listing 6.3: HTML Tags (HTMLTag.java)
package com.heatonresearch.httprecipes.html;
import java.util.*;
public class HTMLTag
{
/*
* The attributes
*/
private Map<String, String> attributes = new HashMap<String,
String>();
/**
* The tag name.
*/
private String name = "";
/*
* Is this both a beginning and ending tag.
*/
private boolean ending;