com.autonomy.utilities
Class EventDrivenXMLParser

java.lang.Object
  |
  +--com.autonomy.utilities.EventDrivenXMLParser
Direct Known Subclasses:
XML2ConfigParser

public class EventDrivenXMLParser
extends java.lang.Object

EventDrivenXMLParser is a simple stream-oriented parser. As the parser recognizes parts of the document it will call the appropriate handler for that part. This class should be extended and the handler methods overridden in order to implement your desired functionality (the handler methods of this class simply print the xml to standard output).

The handler methods are:

Note that, as opposed to the expat parser, no 'user data' structure is passed to the handler methods as class members can be used for this purpose. For an example, see the com.autonomy.client.XML2ACIParser class.

Also note that the xml can be fed to the parser piece by piece as shown in the third example below.

Usage:

EventDrivenXMLParser parser = new EventDrivenXMLParser();

parser.setXML(sXML)

parser.parse();

or

EventDrivenXMLParser parser = new EventDrivenXMLParser(sXML);

parser.parse();

or

EventDrivenXMLParser parser = new EventDrivenXMLParser();

parser.parse(sXML1);
parser.parse(sXML2);
parser.parse(sXML3);


Field Summary
static int PARSE_BAD_TAG
           
static int PARSE_EMPTY_TAG
           
static int PARSE_END_TAG
           
static int PARSE_START_TAG
           
static int PARSE_XML_TAG
           
 
Constructor Summary
EventDrivenXMLParser()
          Default constructor
EventDrivenXMLParser(java.lang.String sXML)
          Constructor for EventDrivenXMLParser.
 
Method Summary
 void charDataHandler(java.lang.String sCharData)
          Called when the parser encounters character data.
 void endElementHandler(java.lang.String sTagName)
          Called when the parser encounters an xml element's end tag.
 void parse()
          Parse the previoulsy specified xml string.
 void parse(java.lang.String sXML)
          Parse the xml string.
 void setXML(java.lang.String sXML)
          Sets sXML as the buffer to be parsed.
 void startElementHandler(java.lang.String sTagName, java.util.Hashtable htAttributes)
          Called when the parser encounters an xml element's start tag.
 void XMLElementHandler(java.lang.String sTagName, java.util.Hashtable htAttributes)
          Called when the parser encounters The
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PARSE_START_TAG

public static final int PARSE_START_TAG
See Also:
Constant Field Values

PARSE_END_TAG

public static final int PARSE_END_TAG
See Also:
Constant Field Values

PARSE_EMPTY_TAG

public static final int PARSE_EMPTY_TAG
See Also:
Constant Field Values

PARSE_BAD_TAG

public static final int PARSE_BAD_TAG
See Also:
Constant Field Values

PARSE_XML_TAG

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

EventDrivenXMLParser

public EventDrivenXMLParser()
Default constructor


EventDrivenXMLParser

public EventDrivenXMLParser(java.lang.String sXML)
Constructor for EventDrivenXMLParser. Sets sXML as the buffer to be parsed.

Parameters:
sXML - the XML to be parsed.
Method Detail

setXML

public void setXML(java.lang.String sXML)
Sets sXML as the buffer to be parsed.

Parameters:
sXML - the XML to be parsed.

parse

public void parse(java.lang.String sXML)
Parse the xml string.

Parameters:
sXML - the XML to be parsed.

XMLElementHandler

public void XMLElementHandler(java.lang.String sTagName,
                              java.util.Hashtable htAttributes)
Called when the parser encounters The tag. This method should be overridden to expand the parser's functionality.

Parameters:
sTagName - the name of the xml element.
htAttributes - a Hashtable containing the xml element's attributes in key-value pairs. The attribute names are used as the table's keys and the attribute values are the corresponding table values. If there are no attributes this Hashtable is empty.

startElementHandler

public void startElementHandler(java.lang.String sTagName,
                                java.util.Hashtable htAttributes)
Called when the parser encounters an xml element's start tag. This method should be overridden to expand the parser's functionality.

Parameters:
sTagName - the name of the xml element.
htAttributes - a Hashtable containing the xml element's attributes in key-value pairs. The attribute names are used as the table's keys and the attribute values are the corresponding table values. If there are no attributes this Hashtable is empty.

endElementHandler

public void endElementHandler(java.lang.String sTagName)
Called when the parser encounters an xml element's end tag. This method should be overridden to expand the parser's functionality.

Parameters:
sTagName - the name of the xml element.

charDataHandler

public void charDataHandler(java.lang.String sCharData)
Called when the parser encounters character data. This method should be overridden to expand the parser's functionality.

Parameters:
sCharData - the character data.

parse

public void parse()
Parse the previoulsy specified xml string. The xml string can be set using either the 1 argument constructor or setXML(String sXML).