org.xwt.util
Class XML

java.lang.Object
  extended byorg.xwt.util.XML

public abstract class XML
extends java.lang.Object

An Event-Driving, Non-Validating XML Parser with Namespace support. A subclass can implement the abstract functions for receiving details about an xml file as it is parsed. To initate a parse, use the parse() function.

IMPLEMENTATION NOTES

As the parser traverses into an element, it adds it to the linked list called elements. However, elements has been pre-filled with instances of the Element inner class. So in the vast majority of cases, the pointer current is moved along one, and the values for the new element are filled into the current object.

This parser supports all the unicode ranges required by the XML Specification. However, it is optimised for well-formed ASCII documents. Documents containing unicode Names and Attributes will take much longer to process, and invalid documents (badly formed Names or invalid attributes) will be run through a test on every single unicode character range before being declared invalid.

IMPLEMENTATION RULES

Other Notes

See Also:
XML-Specification-1.0 http://w3.org/TR/REC-xml

Nested Class Summary
static class XML.Element
          Used as a struct for holding information about a current element, and acts as a linked list entry.
static class XML.MarkupException
          Violation of Markup restrictions in XML Specification - Fatal Error
static class XML.NCException
          Namespace Constraint Violation - Recoverable Error
static class XML.SchemaException
          Schema Violation - Fatal Error
static class XML.WFCException
          Well-Formedness Constraint Violation - Fatal Error
static class XML.XMLException
          Parse or Structural Error
 
Field Summary
static int BUFFER_SIZE
           
 
Constructor Summary
XML()
           
XML(int bSize)
           
 
Method Summary
abstract  void characters(char[] ch, int start, int length)
          Represents a line of character data.
abstract  void endElement(XML.Element e)
          Represents the end of an Element.
 int getCol()
          Returns the column number at the beginning of the last process call.
 int getLine()
          Returns the line number at the beginning of the last process call.
 void parse(java.io.Reader reader)
          Parse given input and call the abstract event functions.
abstract  void startElement(XML.Element e)
          Called when the start of an element is processed.
abstract  void whitespace(char[] ch, int start, int length)
          Represents a line of ignorable whitespace.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUFFER_SIZE

public static final int BUFFER_SIZE
See Also:
Constant Field Values
Constructor Detail

XML

public XML()

XML

public XML(int bSize)
Method Detail

getLine

public int getLine()
Returns the line number at the beginning of the last process call.


getCol

public int getCol()
Returns the column number at the beginning of the last process call.


parse

public final void parse(java.io.Reader reader)
                 throws java.io.IOException,
                        XML.XMLException
Parse given input and call the abstract event functions. Careful with threading, as this function is not synchronized.

Throws:
java.io.IOException
XML.XMLException

startElement

public abstract void startElement(XML.Element e)
                           throws XML.SchemaException
Called when the start of an element is processed.

The array of Attribute names and values may be longer than the number of entries they contain, but all the entries will be packed at the top.

DO NOT store a reference to the attribute arrays, as they are reused by other elements.

Throws:
XML.SchemaException

characters

public abstract void characters(char[] ch,
                                int start,
                                int length)
                         throws XML.SchemaException
Represents a line of character data.

Newlines are all normalised to the Unix \n as per the XML Spec, and a newline will only appear as the last character in the passed array segment.

XML.getLine() and XML.getCol() report the position at the beginning of this character segment, which can be processed in a line-by-line fashion due to the above newline restriction.

Throws:
XML.SchemaException

whitespace

public abstract void whitespace(char[] ch,
                                int start,
                                int length)
                         throws XML.SchemaException
Represents a line of ignorable whitespace.

Throws:
XML.SchemaException

endElement

public abstract void endElement(XML.Element e)
                         throws XML.SchemaException
Represents the end of an Element.

Throws:
XML.SchemaException