日期:2014-05-17 浏览次数:20627 次
public static String format(String str)
??? ??? ??? throws UnsupportedEncodingException, IOException, DocumentException {
??? ??? SAXReader reader = new SAXReader();
??? ??? // System.out.println(reader);
??? ??? StringReader in = new StringReader(str);
??? ??? Document doc = reader.read(in);
??? ??? // System.out.println(doc.getRootElement());
??? ??? OutputFormat formater = OutputFormat.createPrettyPrint();
??? ??? formater.setEncoding("utf-8");
??? ??? StringWriter out = new StringWriter();
??? ??? XMLWriter writer = new XMLWriter(out, formater);
??? ??? writer.write(doc);
??? ??? // writer.close();
??? ??? System.out.println(out.toString());
??? ??? return out.toString();
??? }