Parsing XML with SAX and DOM

When a client sends XML to your server, you must be able to parse the XML document. Obviously, you need either a servlet or a Java Server Page to parse the data. Most of the time, you want to parse the data from a servlet and possibly forward to a JSP to generate any XML output. You can use any of several different parsers to turn XML documents into Java data structures.

There are two different approaches for parsing XML in Java: SAX (Simple API for XML) and DOM (Document Object Model). SAX allows you to handle XML tags in the data as the parser encounters them. In other words, when the parser locates an XML tag, it calls a Java method to handle the tag. It's up to you to decide what to do with it. DOM isn't strictly ...

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.