Java Reference
In-Depth Information
{
buffer.append((char) source.read());
}
return buffer.toString();
If the attribute name is quoted, simply call parseString .
} else
{
return (parseString());
}
Finally, return the result, the attribute name.
Parse Special Characters with parseSpecialCharacter
Certain characters must be encoded when included in HTML documents. Characters
such as greater than are encoded as > . Additionally you can encode ASCII codes. For
example ASCII character 34 could be encoded as " .
The parseSpecialCharacter function handles these character encodings.
This function begins by reading the first character and seeing if it is an ampersand (&). If the
first character is an ampersand then a StringBuilder object is setup to hold the rest
of the character encoding.
char ch = (char) source.read();
if (ch == '&')
{
StringBuilder buffer = new StringBuilder();
Next, a loop is started that will read the rest of the character encoding up to the semico-
lon that ends all character encoding.
do
{
ch = (char) source.read();
if (ch != '&' && ch != ';')
{
buffer.append(ch);
}
If a beginning tag less-than character is found, then the character encoding is invalid, so
we just return an ampersand. This is the best we can do with regards to decoding the char-
acter. The do/while loop will continue until a semicolon is found, or we reach the end of
the file.
if (ch == '<')
return '&';
} while (ch != ';' && (ch != -1));
Search WWH ::




Custom Search