176
Implementing XML Based Applications
Table 4.1
DOM, SAX, and XML Data Binding Programming Models (
continued
)
DOM
SAX
XML Data Binding
High memory usage (The
Low memory usage (only
Intermediate memory usage
document is often completely
events are generated)
(The document is often com
loaded in memory, though
pletely loaded in memory, but
some techniques such as
the Java representation of the
deferred or lazy DOM node
document is more effective
creation may lower the mem
than a DOM representation.
ory usage.)
Nevertheless, some imple
mentations may implement
techniques to lower the mem
ory usage.)
To edit the document (pro
To process parts of the docu
To edit the document (pro
cessing the in memory data
ment (handling relevant
cessing the in memory data
structure)
events)
structure)
To process multiple times
To process the document only
To process multiple times
(document loaded in
once (transient flow of
(document loaded in
memory)
events)
memory)
Processing once the parsing is
Stream processing (start pro
Processing once the parsing is
finished
cessing before the parsing is
finished
finished, and even before the
document is completely read)
4.4.2 Combining XML Processing Techniques
The JAXP API provides support for chaining XML processings: The JAXP
javax.xml.Source
and
javax.xml.Result
interfaces constitute a standard mecha
nism for chaining XML processings. There are implementations of these two inter
faces for DOM, SAX, and even streams; JAXB and other XML processing
technologies, such as JDOM and dom4j, provide their own implementations as well.
Basically, XML processings can be chained according to two designs:
The first design wraps the result of one processing step into a
Source
object
that can be processed by the next step. XML processing techniques that can
produce an in memory representation of their results, such as DOM and JAXB,
lend themselves to this design. This design is often called batch sequential
because each processing step is relatively independent and each runs to com
pletion until the next step begins.
The second design, called stream processing or pipes and filters, creates a
New Page 1