Main Page

Previous Section Next Section

When Not to Use Either

If the task to be performed and the XML data are simple, there usually is no need to use an XML parser; a would suffice. For example, if the task is to read a file and replace a known element value with another, it can be done more quickly, with fewer resources, using Strings rather than SAX and DOM.

The premise that everything must be XML is fundamentally flawed. A common misuse of DOM is reasoning on the following lines. "I'm developing EJBs that will be exposed as services and called by other EJBs across a tier. Therefore, the data passed between them should be XML, and a DOM Document object is best suited for this purpose." Or "My Servlet tier and EJB tier are distributed; therefore, I should use XML for communication between them." While it is true that XML is a portable data format, it is usually not the best choice to communicate with tiers of the same application that never integrate with other applications (see Chapter 2). It is also not the best choice for practical reasons, such as processing, encoding, overheads, and network bandwidth.

Previous Section Next Section

JavaScript Editor Java Tutorials Free JavaScript Editor