Writing a SAX Parser

Two modes are supported for XML parsing in Xerces. You can use SAX or DOM. SAX implements event-driven parsing. DOM loads the entire XML document into memory and hands you a pointer to an object hierarchy that represents it.

You'll write a SAX parser first. To parse this XML file, you need to write a class that extends the org.xml.sax.helpers.DefaultHandler class. This class provides a default set of handlers that are called whenever an event occurs during the parsing of the file. Events include finding the start of the document, encountering a start or end element tag, or reading character data.

You can leave most of these event handlers as is because they implement functionality that you don't need to parse a simple data ...

Get MySQL™ and JSP™ Web Applications: Data-Driven Programming Using Tomcat and MySQL 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.