Java Reference
In-Depth Information
tagName.append((char) source.peek());
source.read();
}
Once the end of the comment tag has been found, append the last characters of the com-
ment and return.
tagName.append("--");
source.read();
source.read();
source.read();
return;
}
If the tag is not a comment, the proceed with extracting the name of the tag. Enter a
while loop that looks for the first non-white space character, or an tag ending greater then
symbol.
// Find the tag name
while (source.peek() != -1)
{
if (Character.isWhitespace((char) source.peek())
|| (source.peek() == '>'))
break;
tagName.append((char) source.read());
}
If a tag has no attributes, then a greater than symbol will be found, which will end the
tag. If the tag has attributes, then a white space character will follow the tag name, followed
by the attributes.
Now prepare to read the attributes, if there are any. First remove any white space, and
then record the tag name.
eatWhitespace();
tag.setName(tagName.toString());
Enter a while loop to read all attributes. If there are no attributes this loop will end
immediately, as it will find a tag ending greater than symbol.
If an attribute is found, call the parseAttributeName function to read the name
of the attribute. The parseAttributeName function will be covered in the next sec-
tion.
// get the attributes
while (source.peek() != '>' && source.peek() != -1)
{
String attributeName = parseAttributeName();
String attributeValue = null;
Search WWH ::




Custom Search