Here you can find the source of writeXmlFile(Document doc, File file)
public static void writeXmlFile(Document doc, File file) throws TransformerConfigurationException, TransformerException
//package com.java2s; /**/* w w w .j a v a 2 s . co m*/ * ***************************************************************************** * * Copyright (c) 2004-2011 Oracle Corporation. * * All rights reserved. This program and the accompanying materials are made * available under the terms of the Eclipse Public License v1.0 which * accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * * Winston Prakash * ****************************************************************************** */ import java.io.File; import javax.xml.transform.OutputKeys; import javax.xml.transform.Result; import javax.xml.transform.Source; 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 writeXmlFile(Document doc, File file) throws TransformerConfigurationException, TransformerException { Source source = new DOMSource(doc); Result result = new StreamResult(file); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); transformer.transform(source, result); } }