DOM is a set of interfaces describing an abstract structure for an XML document. Programs that access document structures through the DOM interface can arbitrarily insert, delete, and rearrange the nodes of an XML document programmatically. DOM and SAX parsers work in different ways. A SAX parser processes the XML document as it parses the XML input stream, passing SAX events to a programmer-defined handler method. A DOM parser, on the other hand, parses the entire input XML stream and returns a Document object.
Document is the programmatic, language-neutral interface that represents a document.
Figures 1 and 2 illustrate this difference between the APIs. The SAX parser calling programmer-defined handler routines Figure 2. In Figure 1, you see the SAX parser calling programmer-defined handler routines for each tag in the XML document. When the parse has completed, you use the methods that are in the Document API to access the contents of the XML tree. One major benefit of the DOM parser is that it provides random access to the structures inside the XML tree.