Implementing XML Based Applications
idated information to create domain specific objects. The cycle of searching
for, extracting, and processing the information can be repeated as many times
as necessary because the DOM tree persists in memory.
There are limitations to the DOM model. DOM was designed to be both a
platform and language neutral interface. Because of this, the Java binding of the
DOM API is not particularly Java friendly. For example, the binding does not use
API. Generally, DOM is slightly easier to use than the
SAX model. However, due to the awkwardness of DOM's Java binding, applica
tion developers who are focused on the implementation of the business logic may
still find DOM difficult to use effectively. For this reason, similarly with SAX,
application developers should be shielded as much as possible from the DOM
In addition, the DOM API prior to version level 3 does not support serializa
tion of DOM trees back to XML. Although some implementations do provide
serialization features, these features are not standard. Thus, developers should
instead rely on XSLT identity transformations, which provide a standard way to
achieve serialization back to XML.
Java developers can also use other technologies, such as JDOM and dom4j,
which have similar functionality to DOM. The APIs of these technologies tend to
be more Java friendly than DOM, plus they interface well with JAXP. They
provide a more elaborate processing model that may alleviate some of DOM's
inherent problems, such as its high memory usage and the limitation of processing
document content only after a document has been parsed.
Although not yet standard for the Java platform (not until JAXP 1.3), the
Xpath API enables using it in conjunction with the DOM programming model.
(The Xpath API can be found along with some DOM implementations such as
Xerces or dom4j.) Developers use Xpath to locate and extract information from a
source document's DOM tree. By allowing developers to specify path patterns to
locate element content, attribute values, and subtrees, Xpath not only greatly sim
plifies, but may even eliminate, tree traversal code. Since Xpath expressions are
strings, they can be easily parameterized and externalized in a configuration file.
As a result, developers can create more generic or reusable document processing