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 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.