172
Implementing XML Based Applications
implementation is layered on top of SAX 2.0 and does not maintain an addi
tional underlying representation of the source document. Additionally, where
DOM represents all XML schema numeric types as strings, JAXB's standard
implementation maps these values directly to much more compact Java numer
ic data types. Not only does this use less memory to represent the same content,
the JAXB approach saves time, because converting between the two represen
tations is not necessary.
E
You previously were implementing XML data binding manually with DOM,
and an XSD schema definition is available.
4.4.1.4
XSLT Programming Model
XSLT is a higher level processing model than the SAX, DOM, and XML data
binding models. Although developers can mimic XSLT by implementing transfor
mations programmatically on top of SAX, DOM, or the XML data binding model,
XSLT does not compare with other processing models and should be regarded as
complementary, to be used along with these other models.
XSLT implements a functional declarative model as opposed to a procedural
model. This requires skills that are quite different from Java programming skills.
For the most part, XSLT requires developers to code rules, or templates, that are
applied when specified patterns are encountered in the source document. The
application of the rules adds new fragments or copies fragments from the source
tree to a result tree. The patterns are expressed in the Xpath language, which is
used to locate and extract information from the source document.
Instead of writing Java code (as with SAX, DOM, and the XML data binding
model), developers using XSLT principally write style sheets, which are them
selves XML documents. (Invoking the XSLT engine, however, does require the
developer to write Java code.) Compared to the other programming models, XSLT
programming gives developers the sort of flexibility that comes with scripting. In
an XML based application, XSLT processing is usually used along with the other
three processing models. The XSLT API available with JAXP provides an
abstraction for the source and result of transformations, allowing the developer
not only the ability to chain transformations but also to interface with other pro
cessing models, such as SAX, DOM, and JAXB technology. To interface with
SAX and DOM, use the classes
SAXSource
,
SAXResult
,
DOMSource
, and
DOMResult
provided by JAXP. To interface with JAXB, use the classes
JAXBSource
and
JAXBResult
.
New Page 1