I often forget it, so make a note How to receive doc and output as xml to file
public static void export(Document doc, File file) throws TransformerException {
TransformerFactory transFactory = TransformerFactory.newInstance();
Transformer transformer = transFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
Source src = new DOMSource(doc);
Result result = new StreamResult(file);
transformer.transform(src, result);
}
Recommended Posts