Java examples for XML:DOM
Save Dom Document to a file path
// This program is free software; you can redistribute it and/or modify it //package com.java2s; import org.w3c.dom.*; import java.io.*; import javax.xml.transform.*; import javax.xml.transform.dom.*; import javax.xml.transform.stream.*; public class Main { public static void SaveDom(Document dom, String filepath) { try {/*from w ww . jav a2 s. c om*/ TransformerFactory transformerFactory = TransformerFactory .newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource domSource = new DOMSource(dom); StreamResult streamResult = new StreamResult( new FileOutputStream(filepath)); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8"); transformer.transform(domSource, streamResult); } catch (Exception e) { throw new RuntimeException(e); } } }