/**
 * 
 */
package com.bcxin.signature.util.common;

import org.dom4j.DocumentHelper;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;

import java.io.StringWriter;

/**
 * @author aluo
 * @desciption
 */
public class XMLUtil {
	/**
	 * @param XMLContent
	 * @return XML formatter
	 * @throws Exception
	 */
	public synchronized static String formatXML(String XMLContent) throws Exception {
		XMLWriter xwoutput = null;
		OutputFormat format = OutputFormat.createPrettyPrint();
		format.setIndentSize(4);
		format.setEncoding("GBK");
		StringWriter resultCollector = new StringWriter();
		xwoutput = new XMLWriter(resultCollector, format);
		xwoutput.write(DocumentHelper.parseText(XMLContent));
		xwoutput.close();
		return resultCollector.getBuffer().toString();
	}
	/**
	 * @param XMLContent
	 * @param encod	
	 * @return XML formatter
	 * @throws Exception
	 */
	public synchronized static String formatXML(String XMLContent,String encod) throws Exception {
		XMLWriter xwoutput = null;
		OutputFormat format = OutputFormat.createPrettyPrint();
		format.setIndentSize(4);
		format.setEncoding(encod);
		StringWriter resultCollector = new StringWriter();
		xwoutput = new XMLWriter(resultCollector, format);
		xwoutput.write(DocumentHelper.parseText(XMLContent));
		xwoutput.close();
		return resultCollector.getBuffer().toString();
	}
}
