读书人

dom4j格式化xml资料

发布时间: 2012-12-20 09:53:21 作者: rapoo

dom4j格式化xml文件
dom4j格式xml并输出为*.xml文件

public static String formatXml(String str) throws DocumentException, IOException {SAXReader reader=new SAXReader();StringReader in=new StringReader(str);Document doc=reader.read(in);OutputFormat formater=OutputFormat.createPrettyPrint();formater.setEncoding("UTF-8");StringWriter out=new StringWriter();XMLWriter writer=new XMLWriter(out,formater);writer.write(doc);writer.close();return out.toString();}

读书人网 >XML SOAP

热点推荐