edu.pdx.cs399J.family
Class XmlParser

java.lang.Object
  extended by edu.pdx.cs399J.family.XmlParser
All Implemented Interfaces:
Parser, EntityResolver, ErrorHandler

public class XmlParser
extends Object
implements Parser

This class parses an XML file generated by XmlDumper and creates a family tree.

Author:
David Whitlock

Field Summary
protected static String publicID
          The Public ID for the Family Tree DTD
protected static String systemID
          The System ID for the Family Tree DTD
 
Constructor Summary
XmlParser(File file)
          Creates a new XML parser that reads its input from the given file.
XmlParser(Reader reader)
          Creates a new XML parser that reads itsinput from the given Reader.
XmlParser(String fileName)
          Creates a new XML parser that reads its input from a file of a given name.
 
Method Summary
 void error(SAXParseException ex)
           
protected static List<String> extractNotesFrom(Element element)
          Extracts a bunch of notes from an Element
protected static String extractTextFrom(Element element)
          Extracts the text from an Element.
 void fatalError(SAXParseException ex)
           
static void main(String[] args)
          Test program.
 FamilyTree parse()
          Parses the specified input source in XML format and from it creates a family tree.
 InputSource resolveEntity(String publicId, String systemId)
          Attempt to resolve the external entity (such as a DTD) described by the given public and system ID.
 void warning(SAXParseException ex)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

systemID

protected static final String systemID
The System ID for the Family Tree DTD

See Also:
Constant Field Values

publicID

protected static final String publicID
The Public ID for the Family Tree DTD

See Also:
Constant Field Values
Constructor Detail

XmlParser

public XmlParser(String fileName)
          throws FileNotFoundException
Creates a new XML parser that reads its input from a file of a given name.

Throws:
FileNotFoundException

XmlParser

public XmlParser(File file)
          throws FileNotFoundException
Creates a new XML parser that reads its input from the given file.

Throws:
FileNotFoundException

XmlParser

public XmlParser(Reader reader)
Creates a new XML parser that reads itsinput from the given Reader. This lets us read from a source other than a file.

Method Detail

parse

public FamilyTree parse()
                 throws FamilyTreeException
Parses the specified input source in XML format and from it creates a family tree.

Specified by:
parse in interface Parser
Throws:
FamilyTreeException - The data source is malformatted

main

public static void main(String[] args)
Test program. Parses an XML file specified on the command line and prints the resulting family tree to standard out.


resolveEntity

public InputSource resolveEntity(String publicId,
                                 String systemId)
                          throws SAXException,
                                 IOException
Attempt to resolve the external entity (such as a DTD) described by the given public and system ID. The external entity is returned as a InputSource

Specified by:
resolveEntity in interface EntityResolver
Throws:
SAXException
IOException

warning

public void warning(SAXParseException ex)
             throws SAXException
Specified by:
warning in interface ErrorHandler
Throws:
SAXException

error

public void error(SAXParseException ex)
           throws SAXException
Specified by:
error in interface ErrorHandler
Throws:
SAXException

fatalError

public void fatalError(SAXParseException ex)
                throws SAXException
Specified by:
fatalError in interface ErrorHandler
Throws:
SAXException

extractNotesFrom

protected static List<String> extractNotesFrom(Element element)
Extracts a bunch of notes from an Element


extractTextFrom

protected static String extractTextFrom(Element element)
Extracts the text from an Element.



Copyright © 2000-2009 Portland State University. All Rights Reserved.