Parsing an XML Document with Java

As you can see, generating an XML document is fairly trivial. Reading an XML document is a little trickier, and that's where a parser comes in. There are two main flavors of XML parsers: SAX and DOM. SAX stands for Simple API for XML and is an event-based parser. When a SAX parser reads through an XML file, it sends an event to a handler class that you write. SAX parsers tend to be fast, but they can be cumbersome to use for complex documents.

Document Object Model (DOM) parsers read the whole document and create a Java representation of the object. The advantage of DOM is that it is usually easier to navigate through the document because you have everything you need. When you use SAX, you must keep track of ...

Get Special Edition Using Java™ 2 Enterprise Edition now with O’Reilly online learning.

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