Using SAX to Parse the File

Now that we're ready to start using SAX, let's take a look at how it actually works.

SAX is much the same way. There are certain events, such as the start of an element, that require certain actions. Our job is to define those actions in such a way that as we read through the ordersUpdate.xml file, we can tally up the items that have been ordered so that later on, we can update the database.

The first thing that we have to realize is that the SAX parser, while crucial to this process, doesn't actually do any of the work we need. All it does is fire off events to an event handler, as in Figure 8.5.

Figure 8.5. A SAX parser has one job: to fire off events to an event handler.

It is our job to create that event handler. ...

Get XML and Java™ from scratch now with O’Reilly online learning.

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