hi,all 一般的网上查到的dom4j格式化,格式出来的xml文件,element的定义和element的text都是处于一行,不太美观,可以加一些参数 StringWriter writer = new StringWriter(); OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("UTF-8"); //format.setIndent(" "); format.setIndent(false); format.setNewlines(false); //如果这个为true,那么空格和换行都被去掉,都在一行 format.setTrimText(false); //如果这个为true,那么element的起始和结束不对齐 format.setPadText(false); format.setLineSeparator(OutputUtilities.lineSeparator); XMLWriter xmlwriter = new XMLWriter(writer, format); try { xmlwriter.write(element); } catch (Exception e) { e.printStackTrace(); }