Simple SAX Example

This example creates a Java program that you can run from the command line. You will be able to specify an XML document to be parsed, and messages will be output onscreen in response to events generated by the SAX parser.


Java, like XML, is case sensitive. All names of interfaces, classes, and so on in the following code must use the correct case if your application is to run correctly.

Listing 18.2 shows a simple SAX example.

Listing 18.2. A Java Program That Provides Screen Output in Response to SAX Events
 import org.xml.sax.XMLReader; import org.xml.sax.SAXException; import org.xml.sax.Attributes; ...

Get Sams Teach Yourself XML in 10 Minutes now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.