Java in a Nutshell, 5th Edition [Electronic resources]

نسخه متنی -صفحه : 1191/ 1072
نمايش فراداده

TransformerHandlerjavax.xml.transform.sax

Java 1.4

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

public interface

TransformerHandler extends org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.ext.LexicalHandler { // Public Instance Methods String

getSystemId ( ); javax.xml.transform.Transformer

getTransformer ( ); void

setResult (javax.xml.transform.Result

result ) throws IllegalArgumentException; void

setSystemId (String

systemID ); }

Returned By

SAXTransformerFactory.newTransformerHandler( )