Java 怎么获取XML转换器(Transformer)

2019年7月29日20:50:32Java 怎么获取XML转换器(Transformer)已关闭评论 375 662字阅读2分12秒

1.简介

Java 怎么获取XML转换器(Transformer)?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */



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

import javax.xml.transform.TransformerFactory;

public class Main {
    private static TransformerFactory transformerFactory;
    private static Transformer transformer;

    public static Transformer getTransformer()
            throws TransformerConfigurationException {
        if (transformer == null) {
            transformer = getTransformerFactory().newTransformer();
        }
        return transformer;
    }

    public static TransformerFactory getTransformerFactory() {
        if (transformerFactory == null) {
            transformerFactory = TransformerFactory.newInstance();
        }
        return transformerFactory;
    }
}

 
编程十万个怎么办