Java XML Element to String elementToStream(Element element, OutputStream out)

Here you can find the source of elementToStream(Element element, OutputStream out)

Description

Write the content of a DOM element to the provided outputstream

License

Apache License

Parameter

Parameter Description
element a parameter
out a parameter

Exception

Parameter Description
TransformerConfigurationException an exception
TransformerException an exception

Declaration

public static void elementToStream(Element element, OutputStream out)
        throws TransformerConfigurationException, TransformerException 

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

public class Main {
    /**//  w  w w  .  ja v a2s.co  m
     * Write the content of a DOM element to the provided outputstream
     * 
     * @param element
     * @param out
     * @throws TransformerConfigurationException
     * @throws TransformerException
     */
    public static void elementToStream(Element element, OutputStream out)
            throws TransformerConfigurationException, TransformerException {
        DOMSource source = new DOMSource(element);
        StreamResult result = new StreamResult(out);
        TransformerFactory transFactory = TransformerFactory.newInstance();
        Transformer transformer = transFactory.newTransformer();
        transformer.transform(source, result);
    }
}

Related

  1. elementToStream(Element element, OutputStream out)
  2. elementToString(Element e)
  3. elementToString(Element el)
  4. elementToString(Element element)
  5. elementToString(Element element)