Java examples for XML:DOM Element
save XML Content to a file
//package com.java2s; import org.w3c.dom.*; import javax.xml.transform.*; import javax.xml.transform.dom.*; import javax.xml.transform.stream.*; public class Main { public static void saveXMLContent(Document d, String path_to_file) { try {//from ww w. j ava2 s . c o m TransformerFactory tff = TransformerFactory.newInstance(); Transformer tf = tff.newTransformer(); tf.setOutputProperty(OutputKeys.INDENT, "yes"); DOMSource ds = new DOMSource(d); StreamResult sr = new StreamResult(path_to_file); tf.transform(ds, sr); } catch (Exception ex) { System.out.println(ex.getMessage()); } } }