SAX Architecture

In addition to the ContentHandler interface, the SAX API provides additional interfaces such as the SAXParserFactory interface. To parse an XML document using a SAX parser, the SAXParserFactory class is used to create an instance of the SAXParser class. The SAXParser class creates an instance of the SAXReader class. The SAXReader instance represents the SAX parser, which processes the XML document and generates events. To handle the events for applications, the SAX API contains the following event handlers:

  • DefaultHandler – Implements the ContentHandler interface by providing the default implementation of the methods specified in the ContentHandler interface
  • ContentHandler – Handles content and invokes callback methods such as startDocument and endDocument whenever it encounters the corresponding tag
  • ErrorHandler – Invokes the appropriate methods whenever an error is encountered while parsing
  • DTDHandler – Is used only when processing a DTD to recognize and act on declarations for an unparsed entity
  • EntityResolver – Identifies the data identified by a namespaceURI
The graphic shows the SAX architecture.
Click the Next button to continue.