Here you can find the source of saveDomToFile(Document doc, String filePath)
Parameter | Description |
---|---|
doc | Document |
filePath | String |
Parameter | Description |
---|---|
Exception | an exception |
public static void saveDomToFile(Document doc, String filePath) throws Exception
//package com.java2s; /*// ww w .j a va2 s. c o m Copyright (c) 2013 eBay, Inc. This program is licensed under the terms of the eBay Common Development and Distribution License (CDDL) Version 1.0 (the "License") and any subsequent version thereof released by eBay. The then-current version of the License can be found at http://www.opensource.org/licenses/cddl1.php and in the eBaySDKLicense file that is under the eBay SDK ../docs directory. */ import java.io.File; import javax.xml.transform.Result; import javax.xml.transform.Source; import javax.xml.transform.Transformer; 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 { /** * Save content of DOM to a file. * @param doc Document * @param filePath String * @throws Exception */ public static void saveDomToFile(Document doc, String filePath) throws Exception { // Write the DOM to file. Source source = new DOMSource(doc); // Prepare the output file File file = new File(filePath); Result result = new StreamResult(file); // Write the DOM document to the file Transformer xformer = TransformerFactory.newInstance().newTransformer(); xformer.transform(source, result); } }