Here you can find the source of newTransformerHandler()
Parameter | Description |
---|---|
TransformerConfigurationException | an exception |
public static TransformerHandler newTransformerHandler() throws TransformerConfigurationException
//package com.java2s; /*//from ww w . ja va 2s. c om * utils-java8 * Copyright (C) 2014 Raffaele Ragni * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.sax.SAXTransformerFactory; import javax.xml.transform.sax.TransformerHandler; public class Main { private static final String UTF8 = "UTF-8"; private static final String YES = "yes"; private static SAXTransformerFactory tf = null; /** * Return a TransformerHandler. * * This is the instance object to be kept as reference for building an XML * document. * * - Encoding: UTF-8 - Indent: Yes - Omit XML declaration: Yes * * @return a TransformerHandler * * @throws TransformerConfigurationException */ public static TransformerHandler newTransformerHandler() throws TransformerConfigurationException { TransformerHandler hd = tf.newTransformerHandler(); Transformer serializer = hd.getTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING, UTF8); serializer.setOutputProperty(OutputKeys.INDENT, YES); serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, YES); return hd; } }