Java tutorial
//package com.java2s; import java.io.File; import java.io.FileOutputStream; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; public class Main { /** * Save document to a file * * @param document : Document to be saved * @param fileName : Represent file name to save * @throws Exception */ public static void saveDocumentTo(Document document, String fileName) throws Exception { File encryptionFile = new File(fileName); try (FileOutputStream fOutStream = new FileOutputStream(encryptionFile)) { TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); DOMSource source = new DOMSource(document); StreamResult result = new StreamResult(fOutStream); transformer.transform(source, result); } } }