Here you can find the source of write(final Document doc, final File file)
public static void write(final Document doc, final File file)
//package com.java2s; /****************************************************************************** * Copyright (c) 2010 Oracle//from w ww .ja va 2 s . c om * 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: * Konstantin Komissarchik - initial implementation and ongoing maintenance ******************************************************************************/ import java.io.File; 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 write(final Document doc, final File file) { try { final DOMSource source = new DOMSource(doc); final StreamResult result = new StreamResult(file); final TransformerFactory factory = TransformerFactory .newInstance(); final Transformer transformer = factory.newTransformer(); transformer.transform(source, result); } catch (TransformerConfigurationException e) { throw new RuntimeException(e); } catch (TransformerException e) { throw new RuntimeException(e); } } }