Java XML Document to Stream writeOutDocument(OutputStream os, Document doc)

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

Description

write Out Document

License

Open Source License

Declaration

public static void writeOutDocument(OutputStream os, Document doc) throws TransformerException, IOException 

Method Source Code


//package com.java2s;

import java.io.IOException;

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

public class Main {
    public static void writeOutDocument(OutputStream os, Document doc) throws TransformerException, IOException {
        DOMSource source = new DOMSource(doc);
        StreamResult sResult = new StreamResult(os);
        TransformerFactory tFactory = TransformerFactory.newInstance();
        Transformer t = tFactory.newTransformer();
        t.setOutputProperty(OutputKeys.ENCODING, "utf-8");
        t.setOutputProperty(OutputKeys.METHOD, "xml");
        t.setOutputProperty(OutputKeys.INDENT, "yes");
        t.transform(source, sResult);/*from w w w  . ja va2  s.  co m*/
        sResult.getOutputStream().close();
    }
}

Related

  1. writeDocument(OutputStream iStream, Element iElement)
  2. writeDocument(OutputStream os, Document document)
  3. writeDocument(OutputStream os, Node node)
  4. writeDocument(OutputStream stream, Document document)
  5. writeDOMDocumentToStream(Document doc, OutputStream stream)
  6. writeTransformedXml(Document doc, OutputStream output, InputStream style)
  7. writeXerces(Document doc, OutputStream out, String encoding)
  8. writeXHTML(Document htmldoc, OutputStream out)
  9. writeXML(Document d, OutputStream os, String sysID)