Java Reference
In-Depth Information
}
// Create a transformer object
Transformer tx = TransformerFactory . newInstance (). newTransformer (
new
new StreamSource ( new
new File ( args [ 1 ]))); // not 0
// Use its transform() method to perform the transformation
tx . transform ( new
new StreamSource ( new
new File ( args [ 0 ])), // not 1
new
new StreamResult ( new
new File ( args [ 2 ])));
}
}
See also the JAXP “XML Transformer,” which does not necessarily use stylesheets, in Gen-
erating Your Own XML with DOM and the XML Transformer .
See Also
An optimization fort XSLT is the use of translets . The translet framework reads a stylesheet
and generates a Translet class, which is a compiled Java program that transforms XML ac-
cording to that particular stylesheet. This eliminates the overhead of reading the stylesheet
each time a document is translated. Translets have been incorporated under the name XSLTC
into the Apache XML Xerces-Java project .
Parsing XML with SAX
Problem
You want to make one quick pass over an XML file, extracting certain tags or other informa-
tion as you go.
Solution
Simply use SAX to create a document handler and pass it to the SAX parser.
Discussion
The XML DocumentHandler interface specifies a number of “callbacks” that your code must
provide. In one sense, this is similar to the Listener interfaces in AWT and Swing, as
Search WWH ::




Custom Search