Here you can find the source of newTransformer()
public static Transformer newTransformer()
//package com.java2s; //License from project: Open Source License import java.util.Properties; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerFactory; public class Main { public static Transformer newTransformer() { try {//w ww.ja va 2s . c o m Transformer transformer = TransformerFactory.newInstance().newTransformer(); Properties properties = transformer.getOutputProperties(); properties.setProperty(OutputKeys.ENCODING, "gb2312"); properties.setProperty(OutputKeys.METHOD, "xml"); properties.setProperty(OutputKeys.VERSION, "1.0"); properties.setProperty(OutputKeys.INDENT, "no"); transformer.setOutputProperties(properties); return transformer; } catch (TransformerConfigurationException tce) { throw new RuntimeException(tce.getMessage()); } } }