Java XML Document Save to File SaveDom(Document dom, String filepath)

Here you can find the source of SaveDom(Document dom, String filepath)

Description

Save Dom

License

Open Source License

Declaration

public static void SaveDom(Document dom, String filepath) 

Method Source Code


//package com.java2s;
// under the terms of the GNU General Public License as published by the

import org.w3c.dom.*;
import java.io.*;

import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;

public class Main {
    public static void SaveDom(Document dom, String filepath) {
        try {//from ww  w. j av a 2 s . co m
            TransformerFactory transformerFactory = TransformerFactory.newInstance();
            Transformer transformer = transformerFactory.newTransformer();

            DOMSource domSource = new DOMSource(dom);

            StreamResult streamResult = new StreamResult(new FileOutputStream(filepath));
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
            transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
            transformer.transform(domSource, streamResult);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. saveDocument(String filename, byte[] document)
  2. saveDocumentToFile(Document doc, File file)
  3. saveDocumentToFile(Document doc, String filename)
  4. saveDOM(Document doc, String filename)
  5. SaveDOM(Document document, String filename)
  6. saveDOM(final Document doc, final OutputStream output)
  7. saveDomToFile(Document doc, String filePath)
  8. saveHumanReadable(Document document, File file)
  9. saveImpl(Document document, StreamResult output, Properties outputProperties)