samples.sax
Class SAXParsingSample

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by samples.sax.SAXParsingSample
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler

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

Parses a FI document using SAXDocumentParser.

The sample parses data/inv1a.finf as specified in the build.xml and handles SAX events to display corresponding content in XML format. The sample class entends DefaultHandler interface making itself a ContentHandler. Since the FastInfoset SAX package does not implement factory, a document parser is instantiated directly. The sample class implements some major event-handling methods as defined in the ContentHandler, such as startDocument, endDocument, startElement, endElement, and characters. In this sample, these methods simply write out the content to System.out.


Constructor Summary
SAXParsingSample()
          Creates a new instance of FIParser
 
Method Summary
 void characters(char[] ch, int start, int length)
          Handles characters event.
 void endDocument()
          Handles endDocument event
 void endElement(String namespaceURI, String localName, String qName)
          Handles endElement event.
static void main(String[] argv)
          Starts the sample.
 void startDocument()
          Handles startDocument event and prints out file header.
 void startElement(String namespaceURI, String localName, String qName, Attributes attributes)
          Handles startElement event.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SAXParsingSample

public SAXParsingSample()
Creates a new instance of FIParser

Method Detail

main

public static void main(String[] argv)
Starts the sample. The sample takes a FI document and parses it using SAXDocumentParser in the fastinfoset package

Parameters:
argv - FI document filename

startDocument

public void startDocument()
                   throws SAXException
Handles startDocument event and prints out file header.

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

endDocument

public void endDocument()
                 throws SAXException
Handles endDocument event

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

startElement

public void startElement(String namespaceURI,
                         String localName,
                         String qName,
                         Attributes attributes)
                  throws SAXException
Handles startElement event. Prints out any text accumulated from the characters event before the element, the element name, and attributes if any.

Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler
Parameters:
namespaceURI - namespace URI
localName - The local name (without prefix), or the empty string if Namespace processing is not being performed.
qName - The qualified name (with prefix), or the empty string if qualified names are not available.
attributes - The specified or defaulted attributes.
Throws:
SAXException

endElement

public void endElement(String namespaceURI,
                       String localName,
                       String qName)
                throws SAXException
Handles endElement event. Prints out any text accumulated from the characters event within the element, and then the end element name.

Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler
Parameters:
namespaceURI - namespace URI
localName - The local name (without prefix), or the empty string if Namespace processing is not being performed.
qName - The qualified name (with prefix), or the empty string if qualified names are not available.
Throws:
SAXException

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws SAXException
Handles characters event. Save the text in a buffer for print-out in start/end element.

Specified by:
characters in interface ContentHandler
Overrides:
characters in class org.xml.sax.helpers.DefaultHandler
Parameters:
ch - The characters
start - The start position in the character array.
length - The number of characters to use from the character array.
Throws:
SAXException


Copyright © 2012 Oracle Corpration. All Rights Reserved.