com.twicom.qdparser
Class XMLReader

java.lang.Object
  extended by com.twicom.qdparser.XMLReader
All Implemented Interfaces:
DocHandler

public class XMLReader
extends java.lang.Object
implements DocHandler

Parses an XML structure producing the equivalent nested class structure

Version:
$Id$
Author:
Kevin Twidle

Field Summary
(package private)  java.util.Stack<TaggedElement> stack
          Holds all the parent elements of the current element
 
Constructor Summary
XMLReader(java.lang.String xml)
          Class constructor that reads the XML from a string
XMLReader(java.lang.String comment, java.io.Reader input)
          Class constructor that reads the XML from a Reader and specifies a comment
XMLReader(java.lang.String comment, java.lang.String xml)
          Class constructor that reads the XML from a string and specifies a comment
XMLReader(java.lang.String comment, java.net.URI uri)
          Class constructor that reads the XML from a URI specified source and specifies a comment
 
Method Summary
 void endDocument()
          Called to indicate the end of the XML document being read
 void endElement(java.lang.String nameSpace, java.lang.String tag)
          Called to indicate the end of a tagged element
static java.io.Reader openResource(java.lang.String name)
          gets a local resource and returns it as a Reader input stream
 TaggedElement parse()
          parses the XML and returns one top level XML class element
static TaggedElement parse(java.lang.String xml)
           
static TaggedElement parse(java.lang.String comment, java.lang.String xml)
           
 void startDocument()
          Called to indicate the start of the XML document being read
 void startElement(java.lang.String nameSpace, java.lang.String tag, java.util.Map<java.lang.String,java.lang.String> attributes, int line, int col)
          Called to indicate the start of a tagged element
 void text(java.lang.String str, boolean cdata, int line, int col)
          Called to indicate that an untagged element has been read
 void text(java.lang.String str, int line, int col)
          Called to indicate that an untagged element has been read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stack

java.util.Stack<TaggedElement> stack
Holds all the parent elements of the current element

Constructor Detail

XMLReader

public XMLReader(java.lang.String xml)
Class constructor that reads the XML from a string

Parameters:
xml - the XML string to be parsed

XMLReader

public XMLReader(java.lang.String comment,
                 java.lang.String xml)
Class constructor that reads the XML from a string and specifies a comment

Parameters:
comment - the comment to be stored with parsed elements
xml - the XML string to be parsed

XMLReader

public XMLReader(java.lang.String comment,
                 java.io.Reader input)
Class constructor that reads the XML from a Reader and specifies a comment

Parameters:
comment - the comment to be stored with parsed elements
input - the XML source to be parsed

XMLReader

public XMLReader(java.lang.String comment,
                 java.net.URI uri)
Class constructor that reads the XML from a URI specified source and specifies a comment

Parameters:
comment - the comment to be stored with parsed elements
uri - the location that contains the XML to be parsed
Method Detail

parse

public static TaggedElement parse(java.lang.String xml)

parse

public static TaggedElement parse(java.lang.String comment,
                                  java.lang.String xml)

parse

public TaggedElement parse()
                    throws XMLParseException,
                           java.io.IOException
parses the XML and returns one top level XML class element

Returns:
the XML element just parsed
Throws:
XMLParseException - if an error occurs when parsing the XML
java.io.IOException - if an error occurs when reading from the input source

startDocument

public void startDocument()
                   throws XMLParseException
Description copied from interface: DocHandler
Called to indicate the start of the XML document being read

Specified by:
startDocument in interface DocHandler
Throws:
XMLParseException - if a semantic error is observed

endDocument

public void endDocument()
                 throws XMLParseException
Description copied from interface: DocHandler
Called to indicate the end of the XML document being read

Specified by:
endDocument in interface DocHandler
Throws:
XMLParseException - if a semantic error is observed

startElement

public void startElement(java.lang.String nameSpace,
                         java.lang.String tag,
                         java.util.Map<java.lang.String,java.lang.String> attributes,
                         int line,
                         int col)
                  throws XMLParseException
Description copied from interface: DocHandler
Called to indicate the start of a tagged element

Specified by:
startElement in interface DocHandler
Parameters:
nameSpace - the namespace part of the tag
tag - the name part of the tag
attributes - the table of attributes for this element
line - the line number where this element was started
col - the column number where this element was started
Throws:
XMLParseException - if a semantic error is observed

endElement

public void endElement(java.lang.String nameSpace,
                       java.lang.String tag)
                throws XMLParseException
Description copied from interface: DocHandler
Called to indicate the end of a tagged element

Specified by:
endElement in interface DocHandler
Parameters:
nameSpace - the namespace part of the tag
tag - the name part of the tag
Throws:
XMLParseException - if a semantic error is observed

text

public void text(java.lang.String str,
                 boolean cdata,
                 int line,
                 int col)
          throws XMLParseException
Description copied from interface: DocHandler
Called to indicate that an untagged element has been read

Specified by:
text in interface DocHandler
Parameters:
str - the value of the untagged element
cdata - true if the element was a CDATA element
line - the line number where this element was started
col - the column number where this element was started
Throws:
XMLParseException - if a semantic error is observed

text

public void text(java.lang.String str,
                 int line,
                 int col)
          throws XMLParseException
Description copied from interface: DocHandler
Called to indicate that an untagged element has been read

Specified by:
text in interface DocHandler
Parameters:
str - the value of the untagged element
line - the line number where this element was started
col - the column number where this element was started
Throws:
XMLParseException - if a semantic error is observed

openResource

public static java.io.Reader openResource(java.lang.String name)
gets a local resource and returns it as a Reader input stream

Parameters:
name - the name of the resource to open
Returns:
the resource opened as a Reader