Java tutorial
//package com.java2s; import java.io.File; import java.util.Properties; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; 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 { public static void save(String paramString, Document paramDocument) throws Exception { DOMSource localDOMSource = new DOMSource(paramDocument); File localFile1 = new File(paramString); File localFile2 = localFile1.getParentFile(); localFile2.mkdirs(); StreamResult localStreamResult = new StreamResult(localFile1); try { TransformerFactory localTransformerFactory = TransformerFactory.newInstance(); Transformer localTransformer = localTransformerFactory.newTransformer(); Properties localProperties = localTransformer.getOutputProperties(); localProperties.setProperty("encoding", "UTF-8"); localProperties.setProperty("indent", "yes"); localTransformer.setOutputProperties(localProperties); localTransformer.transform(localDOMSource, localStreamResult); } catch (TransformerConfigurationException localTransformerConfigurationException) { localTransformerConfigurationException.printStackTrace(); } catch (TransformerException localTransformerException) { localTransformerException.printStackTrace(); } } }