当前位置: 代码迷 >> HTML/CSS >> 格式化一个xml资料在html中显示
  详细解决方案

格式化一个xml资料在html中显示

热度:110   发布时间:2012-09-05 15:19:34.0
格式化一个xml文件在html中显示

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();
??? }

  相关解决方案