Transforming an XML document
In this section, we will develop a Java application for the TrAX to convert an example XML document, catalog.xml
, to an HTML document. The procedure to transform an XML document is as follows:
1. Parse the XML Document.
2. Create a TransformerFactory object.
3. Set an error listener on the TransformerFactory object.
4. Create a Transformer object.
5. Set an error listener on the Transformer object.
6. Set output properties.
7. Transform an XML document.
The example XML document catalog.xml
that we shall transform is listed as follows:
<?xml version="1.0" encoding="windows-1252" ?> <catalog> <journal title="Oracle Magazine" publisher="Oracle Publishing" edition="March-April 2008"> <article section="ORACLE DEVELOPER"> <title>Declarative Data Filtering</title> <author>Steve Muench</author> </article> </journal> <journal title="Oracle Magazine" publisher="Oracle Publishing" edition="November-December 2008">...