dom4j: 用dom4j生成xml后第二行空行的问题

 

只需要指定:

format.setNewLineAfterDeclaration(false);

即可。

例:

OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding("UTF-8");
format.setNewLineAfterDeclaration(false);

这个方法的作用是设置声明之后换不换行的,默认是true,将其置为false即可。

posted @ 2019-01-25 11:13  夜行过客  阅读(889)  评论(0编辑  收藏  举报