geneticWedge.gp.io
Class XMLTreeHandler

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by geneticWedge.gp.io.XMLTreeHandler
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class XMLTreeHandler
extends org.xml.sax.helpers.DefaultHandler

This class can read and extract data from XML files. The data may be present in the file as elements or as attributes, as selected by the mode. Note that all data with the same name will be agglomerated. If an element and an attribute have the same name the mode should therefore be set to ELEMENTS_ONLY or ATTIBUTES_ONLY in order to select the desired data. Element-names are case-insensitive, e.g. 'Data' and 'data' will be treated as the same element


Nested Class Summary
static class XMLTreeHandler.IncludeData
          IncludeData determines which data will be retrieved from the XML file.
 
Constructor Summary
XMLTreeHandler(java.lang.String uri, XMLTreeHandler.IncludeData mode)
          Constructor
 
Method Summary
 void characters(char[] ch, int start, int length)
          Receive notification of character data inside an element.
 void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)
          Receive notification of the end of an element.
 void endPrefixMapping(java.lang.String prefix)
          Receive notification of the end of a Namespace mapping.
 void error(org.xml.sax.SAXParseException e)
          Receive notification of a recoverable parser error.
 void fatalError(org.xml.sax.SAXParseException e)
          Report a fatal XML parsing error.
 java.lang.String[] getData(java.lang.String dataName)
          This method returns all data identified by the variable name dataName.
 java.lang.String[] getDataNames()
          This method returns the variable names retrieved from the XML file.
 void ProcessingInstructions(java.lang.String target, java.lang.String data)
          Receive notification of a processing instruction.
 void SetDocumentLocator(org.xml.sax.Locator loc)
          Receive a Locator object for document events.
 void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)
          Receive notification of the start of an element.
 void startPrefixMapping(java.lang.String prefix, java.lang.String uri)
          Receive notification of the start of a Namespace mapping.
 void warning(org.xml.sax.SAXParseException e)
          Receive notification of a parser warning.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, unparsedEntityDecl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLTreeHandler

public XMLTreeHandler(java.lang.String uri,
                      XMLTreeHandler.IncludeData mode)
Constructor

Method Detail

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
Receive notification of character data inside an element.

Specified by:
characters in interface org.xml.sax.ContentHandler
Overrides:
characters in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

ProcessingInstructions

public void ProcessingInstructions(java.lang.String target,
                                   java.lang.String data)
                            throws org.xml.sax.SAXException
Receive notification of a processing instruction.

Throws:
org.xml.sax.SAXException

startPrefixMapping

public void startPrefixMapping(java.lang.String prefix,
                               java.lang.String uri)
Receive notification of the start of a Namespace mapping.

Specified by:
startPrefixMapping in interface org.xml.sax.ContentHandler
Overrides:
startPrefixMapping in class org.xml.sax.helpers.DefaultHandler

endPrefixMapping

public void endPrefixMapping(java.lang.String prefix)
Receive notification of the end of a Namespace mapping.

Specified by:
endPrefixMapping in interface org.xml.sax.ContentHandler
Overrides:
endPrefixMapping in class org.xml.sax.helpers.DefaultHandler

startElement

public void startElement(java.lang.String namespaceURI,
                         java.lang.String localName,
                         java.lang.String qName,
                         org.xml.sax.Attributes atts)
                  throws org.xml.sax.SAXException
Receive notification of the start of an element.

Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

endElement

public void endElement(java.lang.String namespaceURI,
                       java.lang.String localName,
                       java.lang.String qName)
                throws org.xml.sax.SAXException
Receive notification of the end of an element.

Specified by:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

SetDocumentLocator

public void SetDocumentLocator(org.xml.sax.Locator loc)
Receive a Locator object for document events.


error

public void error(org.xml.sax.SAXParseException e)
           throws org.xml.sax.SAXException
Receive notification of a recoverable parser error.

Specified by:
error in interface org.xml.sax.ErrorHandler
Overrides:
error in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

fatalError

public void fatalError(org.xml.sax.SAXParseException e)
                throws org.xml.sax.SAXException
Report a fatal XML parsing error.

Specified by:
fatalError in interface org.xml.sax.ErrorHandler
Overrides:
fatalError in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

warning

public void warning(org.xml.sax.SAXParseException e)
             throws org.xml.sax.SAXException
Receive notification of a parser warning.

Specified by:
warning in interface org.xml.sax.ErrorHandler
Overrides:
warning in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

getData

public java.lang.String[] getData(java.lang.String dataName)
This method returns all data identified by the variable name dataName. It ignores case, e.g. 'Data' and 'data' will be treated as the same element.


getDataNames

public java.lang.String[] getDataNames()
This method returns the variable names retrieved from the XML file.