Tipworld -> XML
Java and XML: SAX vs. DOM

I've come to realize that XML by itself is not very useful. At some point, you've got to have an application do something with your XML--and that's where XML parsers come into play. There are two methodologies for parsing XML: SAX and DOM. SAX uses callbacks, parsing the XML on an element-by-element basis. DOM reads the XML into an in-memory tree structure and provides APIs to read or manipulate it.

Both SAX and DOM work great, but in different situations. SAX does not have to maintain a memory copy of the XML tree, so it's much easier on memory and CPU usage. On the other hand, DOM provides a simple, more natural tree-based approach to parsing and also allows for manipulating the structure. In the next few tips, I'll show you how to parse XML documents using Java, with a focus on the basics of DOM and SAX.