网上找了不少方法,要么没详细介绍,要么不好使。
以下是对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);
}
};
本文介绍了一种通过重写XMLOutputter的printDeclaration方法,实现XML文件头部信息完美输出的方法。此方法解决了网上常见方法不详尽或无效的问题,确保了XML头部声明的一致性和正确性。
2216

被折叠的 条评论
为什么被折叠?



