O'Reilly logo

XML and Java™ from scratch by Nicholas Chase

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required