Chapter 4 XML Processing
169
To sum up, consider using DOM when any of these circumstances apply:
E
You want to consume or produce documents.
E
You want to manipulate documents and need fine grained control over the doc
ument structure that you want to create or edit.
E
You want to process the document more than once.
E
You want random access to parts of the document. For example, you may want
to traverse back and forth within the document.
E
Memory usage is not a big issue.
E
You want to implement data binding but you cannot use JAXB technology be
cause the document either has no schema or it conforms to a DTD schema def
inition rather than to an XSD schema definition. The document may also be too
complex to use SAX to implement data binding. (See SAX Programming
Model on page 165.)
E
You want to benefit from the flexibility of Xpath and apply Xpath expressions
on DOM trees.
4.4.1.3
XML Data Binding Programming Model
The XML data binding programming model, contrary to the SAX and DOM
models, allows the developer to program the processing of the content of an XML
document without being concerned with XML document representations (infosets).
Using a binding compiler, the XML data binding programming model, as
implemented by JAXB, binds components of a source XSD schema to schema
derived Java content classes. JAXB binds an XML namespace to a Java package.
XSD schema instance documents can be unmarshalled into a tree of Java objects
(called a content tree), which are instances of the Java content classes generated
by compiling the schema. Applications can access the content of the source docu
ments using JavaBeans style get and set accessor methods. In addition, you can
create or edit an in memory content tree, then marshal it to an XML document
instance of the source schema. Whether marshalling or unmarshalling, the devel
oper can apply validation to ensure that either the source document or the docu
ment about to be generated satisfy the constraints expressed in the source schema.
The steps for using JAXB technology schema derived classes to process an
incoming XML document are very simple, and they are as follows:
New Page 1