Event Based Parsing with SAX Under Java

The most straightforward method of parsing XML under Java is with the Simple API for XML (SAX). This section provides examples of the use of SAX with the Java API for XML Processing and focuses on Java-specific issues. Refer to Chapter 15, “Parsing XML Based on Events,” for a more detailed introduction to SAX.

Creating a SAX Parser Instance

In order to parse XML documents with SAX, we first need a method to generate a parser that supports the SAX API. In JAXP, parsing with SAX is made available through the creation of an instance of the JAXP SaxParser class. Because of the extremely general nature of the Java APIs for XML Processing, this is a multistep process.

First, a SAXParserFactory needs to be generated. ...

Get Special Edition Using XML, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.