Skip to Content
Java in a Nutshell, 5th Edition
book

Java in a Nutshell, 5th Edition

by David Flanagan
March 2005
Intermediate to advanced
1254 pages
104h 21m
English
O'Reilly Media, Inc.
Content preview from Java in a Nutshell, 5th Edition

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java in a Nutshell, 8th Edition

Java in a Nutshell, 8th Edition

Benjamin J. Evans, Jason Clark, David Flanagan
Java in a Nutshell, 7th Edition

Java in a Nutshell, 7th Edition

Benjamin J. Evans, David Flanagan
Learning Java, 5th Edition

Learning Java, 5th Edition

Marc Loy, Patrick Niemeyer, Daniel Leuck
Learning Java, 4th Edition

Learning Java, 4th Edition

Patrick Niemeyer, Daniel Leuck

Publisher Resources

ISBN: 0596007736Supplemental ContentErrata Page