Java XML Document Save to File saveToXml(Document doc, OutputStream os)

Here you can find the source of saveToXml(Document doc, OutputStream os)

Description

save To Xml

License

Open Source License

Declaration

public static void saveToXml(Document doc, OutputStream os) throws DOMException, TransformerException 

Method Source Code

//package com.java2s;

import java.io.OutputStream;

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.DOMException;

import org.w3c.dom.Document;

public class Main {
    public static void saveToXml(Document doc, OutputStream os) throws DOMException, TransformerException {
        TransformerFactory factory = TransformerFactory.newInstance();
        // factory.setAttribute("indent-number", new Integer(2));

        Transformer transformer = factory.newTransformer();

        transformer.setOutputProperty(OutputKeys.INDENT, "yes");

        StreamResult result = new StreamResult(os);
        DOMSource source = new DOMSource(doc);
        transformer.transform(source, result);

    }/* w  w  w .  jav  a 2  s .  com*/
}

Related

  1. saveReportToFile(Node node, String documentFileName)
  2. saveTemporaryDocument(Document document, String folderName)
  3. saveToDisk(Document doc, OutputStream out)
  4. saveToFile(Document doc, File f, boolean indent)
  5. saveToFile(String filename, Document document)
  6. saveToXmlStr(Document doc)
  7. saveXML(Document doc, ByteArrayOutputStream outputStreamXML)
  8. saveXML(Document doc, File outfile, boolean indent)
  9. saveXml(Document doc, String filename)