building the full AST of XML document for convenience of the user, SAX parsers operate on each piece of the XML document sequentially, issuing parsing events while making single pass through the input stream.
A SAX parser only needs to report each parsing event as it happens, and normally discards almost all of that information once reported (it does, however, keep some things, for example a list of all elements that have not been closed yet, in order to catch later errors such as end-tags in the wrong order).
The validation of data type information is performed during parsing against an XDR schema or XML Schema or a DTD.
If an external DTD or schema needs to be loaded, the resolver class provided as the Xml Validating Reader.
Such implementations blur the DOM/SAX tradeoffs, but are often very effective in practice.
DTDs and XSD were normally accessed as configuration options in Simple API for XML (SAX), Document Object Model (DOM), and Java™ API for XML Processing (JAXP). Schematron might use the Transformations API for XML(Tr AX); and still other schema languages required programmers to learn still more APIs, even though they were performing essentially the same operation.
Other tasks, such as sorting, rearranging sections, getting from a link to its target, looking up information on one element to help process a later one, and the like, require accessing the document structure in complex orders and will be much faster with DOM than with multiple SAX passes.
It enables you to quickly check that input is roughly in the form you expect and quickly reject any document that is too far away from what your process can handle.
Processing XML documents larger than main memory is sometimes thought impossible because some DOM parsers do not allow it.
Some implementations do not neatly fit either category: a DOM approach can keep its persistent data on disk, cleverly organized for speed (editors such as Soft Quad Author/Editor and large-document browser/indexers such as Dyna Text do this); while a SAX approach can cleverly cache information for later use (any validating SAX parser keeps more information than described above).