Java XML Format formatXML(Transformer transformer)

Here you can find the source of formatXML(Transformer transformer)

Description

This method formats the XML file by omitting the XML Declaration and creating indentations

License

Open Source License

Parameter

Parameter Description
transformer - transformer that is used to process XML

Return

a transformer that omits the XML declaration and performs indentations

Declaration

private static Transformer formatXML(Transformer transformer) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;

public class Main {
    /**//from   w w  w.  j av a2 s. c  o m
     * This method formats the XML file by omitting the XML Declaration and 
     * creating indentations 
     * @param transformer - transformer that is used to process XML
     * @return a transformer that omits the XML declaration and performs indentations  
     * @author Alex Song
     */
    private static Transformer formatXML(Transformer transformer) {
        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
        return transformer;
    }
}

Related

  1. formatXML(byte[] xmlData, int indent)
  2. formatXML(String unformatted)
  3. formatXml(String xml)
  4. formatXML(String xml)
  5. formatXml(String xml)
  6. formatXMLStr(String xml)
  7. prettifyString(String string)
  8. prettyFormat(String input)
  9. prettyFormat(String input)