Code example for TransformerFactory

Methods: newTransformer

0
public class XmlStreamer { 
 
    private static TransformerFactory transformerFactory = TransformerFactory.newInstance();
 
    public static void process(XMLReader xmlReader, PrintStream out) throws Exception {
        Transformer transformer = transformerFactory.newTransformer();
 
        transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty(OutputKeys.METHOD, "xml");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
 
        OutputStream os = System.out;
        transformer.transform(
                new javax.xml.transform.sax.SAXSource(xmlReader, new org.xml.sax.InputSource("")),
                new javax.xml.transform.stream.StreamResult(os));
    } 
 
} 
Stop searching for code, let great code find you!  Add Codota to your java IDE