wyvern.util
Class XMLSimple

java.lang.Object
  extended byorg.xml.sax.helpers.DefaultHandler
      extended bywyvern.util.XMLSimple
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

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

Overrides org.xml.sax.helpers.DefaultHandler to produce an array of hashes for a given XML document. It's similar to what the DOM model produces, but it's more loosely typed, and not as fancy. It's similar to what Perl's XML::Simple->XMLin might produce.

The data structure returned from getDocument() is a tree of XMLSimple.Element objects.

Version:
1.0, Jun 28, 2003
Author:
Steve Yegge

Nested Class Summary
static class XMLSimple.Element
          Simple representation of an XML Element.
 
Constructor Summary
XMLSimple()
           
 
Method Summary
 void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)
          Notification of end of an element.
 void error(org.xml.sax.SAXParseException sx)
          Handles errors.
static void main(java.lang.String[] args)
          Tests it out.
static java.lang.String makePadding(int repeats)
          Creates a string by concatenating N of the same character.
 void printTree()
          Prints the tree that's been built so far for this document.
static XMLSimple.Element readString(java.lang.String xml)
          Reads an xml string.
 void startDocument()
          Notification that the document is beginning.
 void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attrs)
          Constructs a new element, adding it to the children of its parent.
 void warning(org.xml.sax.SAXParseException sx)
          Handles warnings.
 XMLSimple.Element xmlin(java.io.File file)
          Parses an xml file.
 XMLSimple.Element xmlin(java.io.InputStream in)
          Parses an xml input stream.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
characters, endDocument, endPrefixMapping, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startPrefixMapping, unparsedEntityDecl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLSimple

public XMLSimple()
Method Detail

readString

public static XMLSimple.Element readString(java.lang.String xml)
                                    throws java.lang.Exception
Reads an xml string.

Throws:
java.lang.Exception

xmlin

public XMLSimple.Element xmlin(java.io.File file)
                        throws java.lang.Exception
Parses an xml file.

Parameters:
file - a File object representing the file to parse
Throws:
java.lang.Exception

xmlin

public XMLSimple.Element xmlin(java.io.InputStream in)
                        throws java.lang.Exception
Parses an xml input stream.

Throws:
java.lang.Exception

startDocument

public void startDocument()
Notification that the document is beginning. Discards the previous results, if any, and starts over.


startElement

public void startElement(java.lang.String uri,
                         java.lang.String localName,
                         java.lang.String qName,
                         org.xml.sax.Attributes attrs)
Constructs a new element, adding it to the children of its parent. The SAXParser has read the element tag and processed the attributes, if any.


endElement

public void endElement(java.lang.String uri,
                       java.lang.String localName,
                       java.lang.String qName)
Notification of end of an element.


error

public void error(org.xml.sax.SAXParseException sx)
Handles errors.


warning

public void warning(org.xml.sax.SAXParseException sx)
Handles warnings.


makePadding

public static java.lang.String makePadding(int repeats)
Creates a string by concatenating N of the same character.


printTree

public void printTree()
Prints the tree that's been built so far for this document.


main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Tests it out.

Throws:
java.lang.Exception