Code example for SAXTransformerFactory

Methods: newTransformernewXMLFilter

            // --TransformerFactory actually returns a SAXTransformerFactory instance 
            // --We didn't care about that before, because we didn't use the 
            // --SAXTransformerFactory extensions. But now we do, so we cast the result. 
            SAXTransformerFactory stf =
                (SAXTransformerFactory) TransformerFactory.newInstance();
            XMLFilter filter1 = stf.newXMLFilter(new StreamSource(stylesheet1));
            XMLFilter filter2 = stf.newXMLFilter(new StreamSource(stylesheet2));
            // Wire the output of the reader to filter1 
            // and the output of filter1 to filter2 
            // --A filter is a kind of reader 
            // --Setting the parent sets the input reader 
            // --Since a filter is a reader, the "parent" could be another filter 
            // Set up the output stream 
            StreamResult result = new StreamResult(System.out);
            // Set up the transformer to process the SAX events generated 
            // by the last filter in the chain 
            Transformer transformer = stf.newTransformer();
            SAXSource transformSource = new SAXSource(filter2, input);
            transformer.transform(transformSource, result);
        } catch (TransformerConfigurationException tce) {
            // Error generated by the parser 
            System.out.println("\n** Transformer Factory error");
Stop searching for code, let great code find you!  Add Codota to your java IDE