Chapter 4 XML Processing
Generally, when using XML documents, follow these suggestions:
Rely on XML protocols, such as those implemented by JAX RPC and others,
to interoperate with heterogeneous systems and to provide loosely coupled in
Avoid using XML for unexposed interfaces or for exchanges between compo
nents that should be otherwise tightly coupled.
Direct Java serialization of domain specific objects is usually faster than
XML serialization of an equivalent DOM tree or even the Java serialization of the
DOM tree itself (when the DOM implementation supports such a Java serializa
tion). Also, direct Java serialization of the domain specific objects usually results
in a serialized object form that is smaller than the serialized forms of the other two
approaches. The Java serialization of the DOM tree is usually the most expensive
in processing time as well as in memory footprint; therefore it should be used with
extreme care (if ever), especially in an EJB context where serialization occurs
when accessing remote enterprise beans. When accessing local enterprise beans,
you can pass DOM tree or DOM tree fragments without incurring this processing
expense. Table 4.2 summarizes the guidelines for using XML for component
To summarize, when implementing an application which spans multiple con
tainers, keep the following points in mind (also see Table 4.2).
For remote component interaction, Java objects are efficient, serialized XML
although expensive may be used for interoperability. DOM is very expen
sive, and Java serialization of DOM trees is not always supported.
For local component interaction, Java objects are the most efficient and DOM
may be used when required by the application processing model. However, se
rialized XML is to be avoided.
Bind to domain specific Java objects as soon as possible and process these ob
jects rather than XML documents.