Code example for Transformer

Methods: setOutputPropertytransform

0
        tFactory.setAttribute("indent-number", new Integer(4));
 
        Transformer transformer = tFactory.newTransformer();
        DOMSource source = new DOMSource(document);
         
        transformer.setOutputProperty(OutputKeys.METHOD, "xml");   // NOI18N
        transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");  // NOI18N
        transformer.setOutputProperty(OutputKeys.MEDIA_TYPE, "text/xml");  // NOI18N
        transformer.setOutputProperty(OutputKeys.STANDALONE, "yes");  // NOI18N
         
        // indent the output to make it more legible...  
        try { 
            transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");  // NOI18N
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");  // NOI18N
        } catch (IllegalArgumentException e) {
            // the JAXP implementation doesn't support indentation, no big deal 
            //e.printStackTrace(); 
        } 
         
        transformer.transform(source, result);
    } 
     
    /** 
     * DOCUMENT ME! 
     * 
Contextual code suggestions in your IDE  Get Codota for Java