com.aliasi.corpus
Class XMLParser<H extends Handler>

java.lang.Object
  extended by com.aliasi.corpus.Parser<H>
      extended by com.aliasi.corpus.InputSourceParser<H>
          extended by com.aliasi.corpus.XMLParser<H>
Type Parameters:
H - the type of handler to which this parser sends events
Direct Known Subclasses:
GeniaEntityChunkParser, GeniaSentenceParser, MedlineParser, MedlineTextParser, Muc6ChunkParser

public abstract class XMLParser<H extends Handler>
extends InputSourceParser<H>

An XMLParser adapts a handler to be used to handle text extracted from an XML source. The parser implements parse(InputSource) using an XMLReader and an DefaultHandler that is constructed by means of the abstract method getXMLHandler(). The parsing method traps thrown instances of SAXException and converts them to instances of IOException before rethrowing them in order to confrom to the specification of Parser.parse(InputSource).

Since:
LingPipe2.1
Version:
3.9.3
Author:
Bob Carpenter

Constructor Summary
XMLParser()
          Construct an XML parser with a null handler.
XMLParser(H handler)
          Construct an XML parser with the specified handler.
 
Method Summary
protected abstract  DefaultHandler getXMLHandler()
          Return the default handler for SAX events.
 void parse(InputSource inSource)
          Parse the specified input source.
 
Methods inherited from class com.aliasi.corpus.InputSourceParser
parseString
 
Methods inherited from class com.aliasi.corpus.Parser
getHandler, parse, parse, parseString, setHandler
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLParser

public XMLParser()
Construct an XML parser with a null handler.


XMLParser

public XMLParser(H handler)
Construct an XML parser with the specified handler.

Parameters:
handler - Handler to use for parsing.
Method Detail

getXMLHandler

protected abstract DefaultHandler getXMLHandler()
Return the default handler for SAX events. This default handler should wrap the Handler specified for this class and pass events to it extracted from the XML. Typical concrete implementations of this method will extract the underlying handler using Parser.getHandler() and wrap it in a default handler.

This method is called exactly once in each parse method in this class. Thus dynamic updates to the underlying handler may be picked up by this adapter method.

Returns:
SAX handler for XML parsing.

parse

public void parse(InputSource inSource)
           throws IOException
Parse the specified input source. This method uses the default handler returned by getXMLHandler() method as the handler for SAX events generated by parsing the specified input source.

All SAX exceptions thrown by XML parsing are converted to I/O exceptions and rethrown; this step is required by the parent class's specification of this method.

Specified by:
parse in class Parser<H extends Handler>
Parameters:
inSource - Input source to parse.
Throws:
IOException - If there is an I/O exception or a SAX exception raised while parsing.