Name

TransformerHandler

Synopsis

This interface extends org.xml.sax.ContentHandler and related interfaces so that it can consume SAX events generated by a org.xml.sax.SAXReader or org.xml.sax.SAXFilter. Create a TransformerHandler by calling one of the newTransformerHandler( ) methods of a SAXTransformerFactory.

Next, call the setResult( ) method to specify a Result object that describes the result document you’d like the transformation to produce. You may also call getTransformer( ) to get the Transformer object associated with this TransformerHandler if you need to set output properties or parameter values for the transformation.

Now, register the TransformerHandler with the SAXReader or SAXFilter object by calling setContentHandler( ) , setDTDHandler( ), and setProperty( ). `Then you use the property name “http://www.xml.org/sax/properties/lexical-handler” in the call to setProperties( ) to register the TransformerHandler as a org.xml.sax.ext.LexicalHandler for the parser or filter.

Finally, invoke one of the parse( ) methods on your XMLReader or XMLFilter object. This will cause the reader or filter to start parsing the source document and translating it into method calls on the TransformerHandler. The TransformerHandler will transform those calls as specified in the Templates or Source object (if any) that was passed to the original call to newTransformerHandler( ) and generate a result document as directed by the Result object that was passed to setResult( ).

Figure 20-15. javax.xml.transform.sax.TransformerHandler ...

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.