67,513
社区成员
发帖
与我相关
我的任务
分享
public String format(Document document) {
try {
OutputFormat format = new OutputFormat(document);
format.setLineWidth(250);
format.setIndent(2);
format.setOmitXMLDeclaration(false);
format.setOmitDocumentType(false);
format.setIndenting(true);
format.setEncoding("UTF-8");
Writer out = new StringWriter();
XMLSerializer serializer = new XMLSerializer(out, format);
serializer.serialize(document);
return out.toString();
} catch (IOException e) {
throw new RuntimeException(e);
}
}