Here you can find the source of write(Document doc, Result result)
static public void write(Document doc, Result result)
//package com.java2s; /*//from www. java 2s . c om * Copyright (C) 2010 Trustees of the University of Pennsylvania * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS of ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.OutputStream; import java.io.Writer; import javax.xml.transform.OutputKeys; import javax.xml.transform.Result; 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 { static public void write(Document doc, Writer out) { write(doc, new StreamResult(out)); } static public void write(Document doc, OutputStream out) { write(doc, new StreamResult(out)); } static public void write(Document doc, Result result) { TransformerFactory tfact = TransformerFactory.newInstance(); try { Transformer trans = tfact.newTransformer(); trans.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); trans.setOutputProperty(OutputKeys.INDENT, "yes"); trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); trans.setOutputProperty(OutputKeys.METHOD, "xml"); // xml, html, // text trans.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); trans.transform(new DOMSource(doc.getDocumentElement()), result); } catch (TransformerConfigurationException e) { assert (false); // can't happen } catch (TransformerException e) { assert (false); // can't happen } } }