Java Reference
In-Depth Information
In addition to parsing XML, you can use an XML processor to transform XML into some
other format, such as HTML. This is a natural for use in a web servlet: if a given web
browser client can support XML, just write the data as-is, but if not, transform the data into
HTML. We'll look at two approaches to XML transformation: transformation using a generic
XSLT processor and then later some parsing APIs suitable for customized operations on
XML.
If you need to control how an XML document is formatted, for screen or print, you can use
XSL (Extensible Style Language). XSL is a more sophisticated variation on the HTML
stylesheet concept that allows you to specify formatting for particular elements. XSL has two
parts: tree transformation (for which XSLT was designed, though it can also be used inde-
pendently, as we'll see) and formatting (the non-XSLT part is informally known as XSL-FO
or XSL Formatting Objects).
XSL stylesheets can be complex; you are basically specifying a batch formatting language to
describe how your textual data is formatted for the printed page. A comprehensive reference
implementation is FOP (Formatting Objects Processor), which produces Acrobat PDF output
and is available from http://xml.apache.org . Indeed, the third edition of this topic is being
produced using a complex toolchain that converts from AsciiDoc to XML and then XML to
various output formats using XSLT.
When Java first appeared, writing portable XML-based Java programs was difficult because
there was no single standard API. However, for a long time we have had JAXP, the Java API
for XML Processing, which provides standard means for processing XML.
Converting Between Objects and XML with JAXB
Problem
You want to generate XML directly from Java objects, or vice versa.
Solution
One way is to use the Java Architecture for XML Bindings, JAXB.
Search WWH ::




Custom Search