首页 > 技术文章 > 将dom4j格式化为标准的xml字符串

houji 2016-02-23 17:28 原文

StringWriter writer = new StringWriter();

OutputFormat format = OutputFormat.createPrettyPrint();

format.setEncoding("gb2312");

XMLWriter xmlwriter = new XMLWriter( writer, format );

try {

xmlwriter.write(document);

} catch (Exception e) {

e.printStackTrace();

}

return writer.toString();

推荐阅读