Java XML Transform newTransformer()

Here you can find the source of newTransformer()

Description

new Transformer

License

Open Source License

Declaration


public static Transformer newTransformer() 

Method Source Code

//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());
        }
    }
}

Related

  1. getXMLTransformer()
  2. getXmlTransformer()
  3. getXsltTransformer(File xsltFile)
  4. internalTransformWithParams(Reader doc, Templates templates, Result r, boolean trace, String[] params)
  5. newTransformer()
  6. newTransformer()
  7. newTransformer(boolean indented)
  8. newTransformer(int indent)
  9. newTransformerFactory()