23.5. SAX Example 2: Counting Book Orders

One of the advantages of SAX over DOM is that SAX does not require you to process and store the entire document; you can quickly skip over the parts that do not interest you. The following example looks for sections of an XML file that look like this:


The idea is that the program will count up how many copies of Core Web Programming Second Edition (you did recognize that ISBN number, right?) are contained in a set of orders. Thus, it can skip over most elements. Since SAX, unlike DOM, does not store anything automatically, we need to take care of storing the pieces of data that are of interest. The one difficulty ...

Get Core Web Programming, Second Edition now with the O’Reilly learning platform.

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