com.cometway.xml
Class XMLParser

java.lang.Object
  extended by com.cometway.xml.XMLParser
Direct Known Subclasses:
XMLFileParser

public class XMLParser
extends java.lang.Object

XMLParser. This class parses min xml into one of 4 kinds of tokens: XML.EMPTY_ELEMENT_TAG, XML.START_TAG, XML.END_TAG, and XML.ELEMENT_CONTENT. The XMLParser is instantiated with a source and characters will be read from this source via a Stream. Successive calls to the nextToken() method will return the next parsed tokens from the stream. Some options can be set, to ignore whitespace or to decode xml 1.0 escape codes in the XML.ELEMENT_CONTENT tokens. A EOFException will be thrown if the stream has reached the end.

See Also:
XMLToken

Field Summary
protected  java.io.InputStream dataSource
           
protected  boolean decodeEscapeCodes
          Setting this field to true will cause the parser to decode XML 1.0 escape codes in the text
protected  boolean ignoreWhitespace
          Setting this value to true will cause the parse to remove the whitespace it finds around tags and text.
 
Constructor Summary
XMLParser(java.io.InputStream source)
          Parse XML from an input stream
XMLParser(java.lang.String source)
          Parse XML from a String.
 
Method Summary
 void close()
          Closes the InputStream used by the parser.
 XMLToken nextElementContent()
          Returns the next token if it's type is XML.ELEMENT_CONTENT.
 XMLToken nextEmptyElementTag()
          Returns the next token if it's type is XML.EMPTY_ELEMENT_TAG.
 XMLToken nextEndTag()
          Returns the next token if it's type is XML.END_TAG.
 XMLToken nextStartTag()
          Returns the next token if it's type is XML.START_TAG.
 XMLToken nextToken()
          This method returns the next parsed token from the source Stream.
 XMLToken nextToken(java.lang.String data)
          Returns the next token if it matches the specified data.
 void setDecodeEscapeCodes(boolean decodeEscapeCodes)
          The parser will decode escape codes within element content when this option is set to true (default is true).
 void setIgnoreWhitespace(boolean ignoreWhitespace)
          The parser will ignore whitespace before and after element content when this option is set to true (default is true).
 void setLength(int length)
          This sets how many characters is to be read from the input source.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ignoreWhitespace

protected boolean ignoreWhitespace
Setting this value to true will cause the parse to remove the whitespace it finds around tags and text.


decodeEscapeCodes

protected boolean decodeEscapeCodes
Setting this field to true will cause the parser to decode XML 1.0 escape codes in the text


dataSource

protected java.io.InputStream dataSource
Constructor Detail

XMLParser

public XMLParser(java.lang.String source)
Parse XML from a String.


XMLParser

public XMLParser(java.io.InputStream source)
Parse XML from an input stream

Method Detail

close

public void close()
           throws XMLParserException
Closes the InputStream used by the parser.

Throws:
XMLParserException

setIgnoreWhitespace

public void setIgnoreWhitespace(boolean ignoreWhitespace)
The parser will ignore whitespace before and after element content when this option is set to true (default is true).


setDecodeEscapeCodes

public void setDecodeEscapeCodes(boolean decodeEscapeCodes)
The parser will decode escape codes within element content when this option is set to true (default is true).


setLength

public void setLength(int length)
This sets how many characters is to be read from the input source.


nextToken

public XMLToken nextToken()
                   throws XMLParserException
This method returns the next parsed token from the source Stream. The tokens can be one of 4 types: a XML.EMPTY_ELEMENT_TAG, XML.START_TAG, XML.END_TAG, or XML.ELEMENT_CONTENT. This method will read as many characters as needed until its buffer satisfies one of the 4 tokens. If the end of the stream is reached, an EOFException will be thrown. If an error in the stream is caught, an IOException will be thrown.

Throws:
XMLParserException

nextToken

public XMLToken nextToken(java.lang.String data)
                   throws XMLParserException
Returns the next token if it matches the specified data.

Throws:
XMLParserException - if it does not match the specified data or there is a problem.

nextStartTag

public XMLToken nextStartTag()
                      throws XMLParserException
Returns the next token if it's type is XML.START_TAG.

Throws:
XMLParserException - if it's type is not XML.START_TAG or there is a problem.

nextEndTag

public XMLToken nextEndTag()
                    throws XMLParserException
Returns the next token if it's type is XML.END_TAG.

Throws:
XMLParserException - if it's type is not XML.END_TAG or there is a problem.

nextElementContent

public XMLToken nextElementContent()
                            throws XMLParserException
Returns the next token if it's type is XML.ELEMENT_CONTENT.

Throws:
XMLParserException - if it's type is not XML.ELEMENT_CONTENT or there is a problem.

nextEmptyElementTag

public XMLToken nextEmptyElementTag()
                             throws XMLParserException
Returns the next token if it's type is XML.EMPTY_ELEMENT_TAG.

Throws:
XMLParserException - if it's type is not XML.EMPTY_ELEMENT_TAG or there is a problem.