LogFormat.java 文件源码

java
阅读 25 收藏 0 点赞 0 评论 0

项目:Renrentou 作者:
public static String formatXml(String xml) {
    String formatted = null;
    if (xml == null || xml.trim().length() == 0) {
        return formatted;
    }
    try {
        Source xmlInput = new StreamSource(new StringReader(xml));
        StreamResult xmlOutput = new StreamResult(new StringWriter());
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount",
                String.valueOf(XML_INDENT));
        transformer.transform(xmlInput, xmlOutput);
        formatted = xmlOutput.getWriter().toString().replaceFirst(">", ">"
                + XPrinter.lineSeparator);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return formatted;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号