JAXP SAX
External
Internal
Overview
A SAX parser implements event-driven, push parsing.
To use a SAX parser, use SAXParserFactory to generate a parser instance. The actual implementation of the parser implements the SAXParser interface and is determined by the value of javax.xml.parsers.SAXParserFactory system property. Then call parsers's parse() method. The parser contains a SAXReader instance, which invokes callback methods the application must implement. The methods are defined by the ContentHandler, ErrorHandler, DTDHandler and EntityResolver interfaces.
When an XML tag is recognized, the parser invokes the corresponding methods (startDocument(), startElement()), ...) on the ContentHandler implementation.
The ErrorHandler implementation is messaged on various parsing errors. The default implementation is rudimentary, if a more nuanced behavior is necessary, the handler must be implemented.
For a working example of SAX parsing, see SAX Example below.
SAX Example
Component Packages
- javax.xml.parsers
- org.xml.sax the basic SAX API.