When is it appropriate to use SAX and when is it appropriate to use the DOM?

Witt Sparks

The DOM is simpler to implement, but because it reads the entire XML document into a tree structure in memory, it is not appropriate for extremely large documents or on memory-constrained devices such as PDAs and cell phones.

SAX uses an event driven model to notify the application of document elements as it's reading the document. This makes it more suitable if memory is a concern, or for large documents, because any content your application doesn't care about can be immediately discarded without consuming memory. Because it is event driven, it can be more difficult to set up the appropriate callback routines, etc. than to use the DOM.