DOM Versus SAX
DOM uses the principle of reading the entire XML document into memory, as described before. SAX, however, is more like an event parsing mechanism because it fires or triggers events depending on where it is in the course of parsing the document.
Because DOM stores the entire document as a memory map, it is not resource friendly, and hence we need to be careful in deciding when to use it. Ideally, if there is need for referring to the parameter or configuration variable values in most transactions, DOM is the answer. Consider, for example, that you have a typical need to refer to a mapping that might correlate a URI with actual IP addresses. Whenever the user triggers a request, the system has to look up in this map file and go to that IP accordingly. A DOM model is best suited for this application. The trade-off is that even though we would have thousands of such mappings defined, they must be readily available to go to the right IP. This typical requirement is a must for some designs in the distributed world, like a lookup server as described in Chapter 13, "Cross-Platform and Diverse System Integration," and Chapter 14, "Implementing an ERP System," of Part II, "Case Studies."
SAX, on the other hand, creates no such memory map and hence has a smaller memory "footprint." A typical application dynamically reads an XML file and represents coordinates that plot on a white board. This would be a requirement for a typical graphics view program or chat application supporting a white board type of interface. Then, the requirement narrows to plotting only the graphic from the sets of coordinates. Hence, SAX is ideal for such an application.
XML is very flexible and represents one data set in numerous formats, which creates the usability crisis. Also, the way information is bundled has to be specified and essentially needs to follow a standard so that the receiving system will know how to locate information within the stream. This calls for some specialized standard message formats like SOAP.
Further, as XML has diminished as a cross system protocol for maximum flexibility, we will look into aspects of using XML for connecting and communicating with remote systems.