我使用这段代码来启用换行符:
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
但我得到以下输出:
<?xml version="1.0" encoding="UTF-8"?><root>
<child>aaaa</child>
</root>
我想在根元素之前有换行符。我该怎么办?
最佳答案
试试这个
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount","2");
关于java - 如何在<?xml版本="1.0"编码="UTF-8"?>之后强制java xml dom生成换行符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11275988/