SAX Parser

SAX Parser

  • SAX (the Simple API for XML) is an event-based parser for xml documents.
  • The parser tells the application what is in the document by notifying the application of a stream of parsing events.
  • Application then processes those events to act on data.
 SAX Parser

Learn XML - XML tutorial - SAX Parser - XML examples - XML programs

SAX Parser - Event Based Parser

  • Event-based parsers send parsing events directly to application logic (begin and end of element but not its attributes).
  • If application logic interested in element it requests additional data from parser.
  • Effective when application needs only sequential access to certain kinds of elements.
 Event Based Parser

Learn XML - XML tutorial - Event Based Parser - XML examples - XML programs

Why SAX ?

  • For applications that are not so XML-centric, an object-based interface is less appealing.
  • Efficiency : lower level than object-based interfaces
  • Event-based interface consumes fewer resources than an object-based one
  • With an event-based interface, the application can start processing the document as the parser is reading it

Parsing XML : SAX

  • SAX is an interface to the XML parser based on streaming and call-backs.
  • We need to implement the HandlerBase interface :
    • StartDocument, endDocument
    • StartElement, endElement
    • Characters
    • Warning, error, fatalError
 Parsing XML using Sax

Learn XML - XML tutorial - Parsing XML using Sax - XML examples - XML programs

Limitations of SAX

  • With SAX, it is not possible to navigate through the document as you can with a DOM.
  • The application must explicitly buffer those events is interested in it.

Related Searches to SAX Parser