23.3. Parsing XML Documents with SAX 2.0

DOM processing is relatively straightforward since the DOM classes do all the “real” parsing—you just have to look through the parsed result for the data you want. However, DOM can be quite wasteful if you only care about a small part of the document. For example, suppose that you want to extract the first word from an XML document representing an entire dictionary. DOM would require you to parse and store the entire XML document (which could be huge in this case). With SAX, you need only store the parts you care about and can stop parsing whenever you want. On the other hand, SAX is a bit more work. The idea is that the system tells you when certain parsing events such as finding a start tag (<language ...

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

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