Here you can find the source of writeDocumentToFile(Document document, String filePathname, String method, int indent)
Parameter | Description |
---|---|
document | the document object. |
filePathname | the path name of the file to be written to. |
method | the output method: for instance html, xml, text |
indent | amount of indentation. -1 to use the default. |
Parameter | Description |
---|---|
TransformerException | if an exception occurs. |
IOException | if an IO exception occurs. |
public static void writeDocumentToFile(Document document, String filePathname, String method, int indent) throws TransformerException, IOException
//package com.java2s; //License from project: Apache License import java.io.FileOutputStream; import java.io.IOException; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; 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 { /**/* w ww .j a va 2 s .c o m*/ * Write the document object to a file. * * @param document * the document object. * @param filePathname * the path name of the file to be written to. * @param method * the output method: for instance html, xml, text * @param indent * amount of indentation. -1 to use the default. * @throws TransformerException * if an exception occurs. * @throws IOException * if an IO exception occurs. */ public static void writeDocumentToFile(Document document, String filePathname, String method, int indent) throws TransformerException, IOException { Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.METHOD, method); transformer.transform(new DOMSource(document), new StreamResult(new FileOutputStream(filePathname))); } }