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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.