kiwi.text
Class SGMLParser
java.lang.Object
|
+--kiwi.text.SGMLParser
- public class SGMLParser
- extends Object
A parsing engine for SGML markup. SGMLParser
tokenizes SGML
markup into a series of tags and strings, which are passed to
a consumer in sequence. This class can be used to implement a simple HTML
document parser. Here is a trivial example that recognizes a few HTML tags
read from standard input:
class HTMLParser implements SGMLConsumer
{
SGMLParser parser;
HTMLParser()
{
parser = new SGMLParser(new InputStreamReader(System.in), this);
}
void parse()
{
try
{
parser.parse();
}
catch(IOException ex)
{
System.out.println("End of input, or other error.");
}
}
public void processString(String s)
{
System.out.println("String: " + s);
}
public void processElement(SGMLElement e)
{
String tag = e.getTag();
if(tag.equalsIgnoreCase("b"))
System.out.println("Bold " + (tag.isEnd() ? "end" : "begin"));
else if(tag.equalsIgnoreCase("center"))
System.out.println("Centering " + (tag.isEnd() ? "end" : "begin"));
}
}
- Version:
- 1.1.1 (05/98)
- Author:
- Mark Lindner, Alex Lian (bug fixes), Eric Lunt (bug fixes), PING Software Group
Method Summary |
void |
parse()
Parse the input. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
SGMLParser
public SGMLParser(Reader reader,
SGMLConsumer consumer)
- Construct a new
SGMLParser
.
- Parameters:
reader
- The reader to parse input from.consumer
- The SGMLConsumer
that will process strings
and SGML elements decoded from the reader.
parse
public void parse()
throws IOException
- Parse the input. Data is read from the input stream and tokenized streams
and tags are passed to the consumer until there is no more data available
on the stream.
- Throws:
- IOException - If an error occurs on the input stream.