Java XML Transform createIndentingTransformer()

Here you can find the source of createIndentingTransformer()

Description

create Indenting Transformer

License

Open Source License

Return

a transformer that indents entries by 4 characters (never null)

Declaration

public static Transformer createIndentingTransformer() 

Method Source Code

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

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

import javax.xml.transform.TransformerFactory;

public class Main {
    private static final TransformerFactory TRANSFORMER_FACTORY = TransformerFactory
            .newInstance();/*w  ww .  j  a v  a 2  s.c  o  m*/

    /**
     * @return a transformer that indents entries by 4 characters (never null)
     */
    public static Transformer createIndentingTransformer() {
        Transformer transformer;
        try {
            TRANSFORMER_FACTORY.setAttribute("indent-number", 4);
            transformer = TRANSFORMER_FACTORY.newTransformer();
        } catch (final Exception e) {
            throw new IllegalStateException(e);
        }
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty(
                "{http://xml.apache.org/xslt}indent-amount", "4");
        return transformer;
    }
}

Related

  1. applyXSLTTransform(final String xslt, final Reader input, final Writer output)
  2. buildXmlTransformer()
  3. createOutputTransformer(String encoding, boolean omitXmlDeclaration, boolean indent, int indentAmount)
  4. createPrettyTransformer(int indent)
  5. createTransformer()
  6. createTransformer()