Java XML Transform createPrettyTransformer(int indent)

Here you can find the source of createPrettyTransformer(int indent)

Description

Creates a Transformer with a configuration that affects the output of the transformed xml.

License

Open Source License

Parameter

Parameter Description
indent the amount of indentation

Exception

Parameter Description

Return

the transformer

Declaration

public static Transformer createPrettyTransformer(int indent) throws TransformerConfigurationException 

Method Source Code

//package com.java2s;
/**/*from   w w  w  . jav  a 2  s.c  om*/
 * TL Manager
 * Copyright (C) 2015 European Commission, provided under the CEF programme
 *
 * This file is part of the "TL Manager" project.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

import javax.xml.transform.OutputKeys;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;

import javax.xml.transform.TransformerFactory;

public class Main {
    /**
     * Creates a <code>Transformer</code> with a configuration that affects the output of the transformed xml.
     *
     * @param indent the amount of indentation
     * @return the transformer
     * @throws javax.xml.transform.TransformerConfigurationException
     */
    public static Transformer createPrettyTransformer(int indent) throws TransformerConfigurationException {
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", String.valueOf(indent));

        return transformer;
    }
}

Related

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