网上找了不少方法,要么没详细介绍,要么不好使。
以下是对XMLOutPutter重写printDeclaration方法,可以完美输出xml头部信息
public static final XMLOutputter XMLOUTPUT = new XMLOutputter(Format.getPrettyFormat()) {
@Override
protected void printDeclaration(Writer out, Document doc, String encoding) throws IOException {
out.write("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?> ");
out.write(STANDARD_LINE_SEPARATOR);
}
};