java出来xml相关API的工具类_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > java出来xml相关API的工具类

java出来xml相关API的工具类

 2015/3/20 19:07:12  黄伟财  程序员俱乐部  我要评论(0)
  • 摘要:packagecom.cn.xml;importjavax.xml.parsers.DocumentBuilder;importjavax.xml.parsers.DocumentBuilderFactory;importjavax.xml.transform.Transformer;importjavax.xml.transform.TransformerFactory;importorg.w3c.dom.Document;publicclassXMLParseUtil
  • 标签:API 工具 Java XML
class="java" name="code">package com.cn.xml;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import org.w3c.dom.Document;

public class XMLParseUtil {
	private static final Document document=bulidDocument();  //获取document解析对象
	
	private static final Transformer transformer=buildTransformer();  //获取transformer转换对象
	
	
	private static Document bulidDocument(){
		
		try{
			DocumentBuilderFactory dFactory=DocumentBuilderFactory.newInstance();
			DocumentBuilder dBuilder=dFactory.newDocumentBuilder();
			return dBuilder.newDocument();
		}catch(Throwable ex){
			throw new ExceptionInInitializerError(ex);  
		}
		
	}
	
	public static Document getDocument(){
		return document;
	}
	
	private static Transformer buildTransformer(){
		try{
			TransformerFactory tFactory=TransformerFactory.newInstance();
			return tFactory.newTransformer();
		}catch(Throwable ex){
			throw new ExceptionInInitializerError(ex);  
		}
	}
	
	public static Transformer getTransformer(){
		return transformer;
	}

}

?

上一篇: java导出pdf 下一篇: 各种免费api
发表评论
用户名: 匿名