de.zeigermann.xpa
Class XMLFragmentParser

java.lang.Object
  |
  +--de.zeigermann.xpa.XMLFragmentParser

public class XMLFragmentParser
extends Object

Rudimentary non-validating XML parser.

Limitations:


The good thing about some of these limitations is, that the parsed XML can almost be written literally unmodified.


Constructor Summary
protected XMLFragmentParser(DataInputStream in, XMLFragmentHandler handler)
          Creates a new parser with a byte stream of UTF-8 encoded characters as input.
  XMLFragmentParser(InputBuffer in, XMLFragmentHandler handler)
          Creates a new parser with an input buffer as input.
  XMLFragmentParser(InputStream in, XMLFragmentHandler handler)
          Creates a new parser with a byte stream of UTF-8 encoded characters as input.
  XMLFragmentParser(Reader in, XMLFragmentHandler handler)
          Creates a new parser with a reader as input.
protected XMLFragmentParser(de.zeigermann.xpa.XMLLexer lexer, XMLFragmentHandler handler)
          Creates a new parser using lexer for actual parsing.
 
Method Summary
 void parse()
          Parses the full XML document defined as input by constructor and notifies handler set by setHandler(de.zeigermann.xpa.XMLFragmentHandler) or constructor upon identified XML tokens.
 void parse(XMLFragmentHandler handler)
          Parses the full XML document defined as input by constructor and notifies handler upon identified XML tokens.
 boolean pullNextToken()
          Requests the next token notifying event to handler set by setHandler(de.zeigermann.xpa.XMLFragmentHandler).
 void setHandler(XMLFragmentHandler handler)
          Sets the handler to be notified upon identified XML tokens.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLFragmentParser

public XMLFragmentParser(Reader in,
                         XMLFragmentHandler handler)
Creates a new parser with a reader as input.

Parameters:
in - the reader to parse XML from
handler - the handler to notify upon identified XML tokens

XMLFragmentParser

public XMLFragmentParser(InputStream in,
                         XMLFragmentHandler handler)
Creates a new parser with a byte stream of UTF-8 encoded characters as input.

Parameters:
in - the input stream to parse XML from
handler - the handler to notify upon identified XML tokens

XMLFragmentParser

public XMLFragmentParser(InputBuffer in,
                         XMLFragmentHandler handler)
Creates a new parser with an input buffer as input.

Parameters:
in - the input buffer to parse XML from
handler - the handler to notify upon identified XML tokens

XMLFragmentParser

protected XMLFragmentParser(DataInputStream in,
                            XMLFragmentHandler handler)
Creates a new parser with a byte stream of UTF-8 encoded characters as input.

Parameters:
in - the data input stream to parse XML from
handler - the handler to notify upon identified XML tokens

XMLFragmentParser

protected XMLFragmentParser(de.zeigermann.xpa.XMLLexer lexer,
                            XMLFragmentHandler handler)
Creates a new parser using lexer for actual parsing.

Parameters:
lexer - the lexer used to parse (fully initialized with input)
handler - the handler to notify upon identified XML tokens
Method Detail

setHandler

public void setHandler(XMLFragmentHandler handler)
Sets the handler to be notified upon identified XML tokens.

Parameters:
handler - the handler to notify upon identified XML tokens

parse

public void parse()
           throws XPAParseException
Parses the full XML document defined as input by constructor and notifies handler set by setHandler(de.zeigermann.xpa.XMLFragmentHandler) or constructor upon identified XML tokens.

XPAParseException

parse

public void parse(XMLFragmentHandler handler)
           throws XPAParseException
Parses the full XML document defined as input by constructor and notifies handler upon identified XML tokens.

Parameters:
handler - the handler to notify upon identified XML tokens
XPAParseException

pullNextToken

public boolean pullNextToken()
                      throws XPAParseException
Requests the next token notifying event to handler set by setHandler(de.zeigermann.xpa.XMLFragmentHandler).
Calling this method repeatedly (until false is returned is an alternative to calling parse().

This method is useful when you want to drive this parser in passive mode, i.e. asking for (pulling) tokens instead of waiting for the parser to eventually call your handler.

Returns:
true if a token was found, false if we reached EOF
XPAParseException


Copyright 1999-2003 Oliver Zeigermann. All Rights Reserved.