OutputFormat XML_FORMAT = new OutputFormat();
File outFile = new File(myConfig.getSaeExportPath());
if(!outFile.exists()){
    outFile.mkdirs();
}
OutputStream xmlOs = new FileOutputStream(outFile+File.separator+"test.xml");
XMLWriter xmlWriter = new XMLWriter(xmlOs,XML_FORMAT);
//xmlWriter.setEscapeText(false);
xmlWriter.write(doc);

XML_FORMAT 不要设置任何

导出的文件如下:没有格式

dom4j去除元素内多余空格_干货

 

 但XML_FORMAT改成如下,生成的xml就是有格式的

//用于格式化xml内容和设置头部标签
XML_FORMAT = OutputFormat.createPrettyPrint();dom4j去除元素内多余空格_xml_02