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

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

Description

write Document

License

Apache License

Declaration

public static OutputStream writeDocument(Document doc, OutputStream os) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.OutputStream;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
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 OutputStream writeDocument(Document doc, OutputStream os) {
        TransformerFactory tFactory = TransformerFactory.newInstance();
        Transformer transformer;//from w w  w  .  j a va 2s.c o m
        try {
            transformer = tFactory.newTransformer();
            DOMSource source = new DOMSource(doc);
            StreamResult result = new StreamResult(os);
            transformer.transform(source, result);
        } catch (TransformerConfigurationException e) {
            e.printStackTrace();
        } catch (TransformerException e) {
            e.printStackTrace();
        }
        return os;
    }
}

Related

  1. dumpDoc(Document domTree, PrintStream out)
  2. dumpToStream(Document doc, OutputStream out)
  3. toXml(Document doc, OutputStream out)
  4. write(Document doc, OutputStream out, String enc)
  5. write(Document document, OutputStream byteStream)
  6. writeDocument(Document doc, OutputStream os)
  7. writeDocument(Document doc, Transformer transformer, OutputStream out)
  8. writeDocument(Document document, OutputStream documentOutputStream)
  9. writeDocument(Document document, OutputStream os)