Java XML Document Print printXml(Document xml, Writer out)

Here you can find the source of printXml(Document xml, Writer out)

Description

print Xml

License

Open Source License

Declaration

public static void printXml(Document xml, Writer out)
            throws TransformerException, UnsupportedEncodingException 

Method Source Code

//package com.java2s;
//License from project: GNU General Public License 

import java.io.OutputStream;
import java.io.OutputStreamWriter;

import java.io.UnsupportedEncodingException;
import java.io.Writer;

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 printXml(Document xml, Writer out)
            throws TransformerException, UnsupportedEncodingException {
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.METHOD, "xml");
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");

        transformer.transform(new DOMSource(xml), new StreamResult(out));
    }/*from ww  w . j a v  a 2 s. co  m*/

    public static void printXml(Document response, OutputStream out)
            throws UnsupportedEncodingException, TransformerException {
        printXml(response, new OutputStreamWriter(out));
    }
}

Related

  1. printDOM(File file, Document doc, String encoding)
  2. printElements(Document doc)
  3. printElements(Document dom)
  4. printPI(Document doc, PrintStream pstrm)
  5. printXML(Document doc)
  6. printXmlDocument(Document doc)
  7. printXMLDocument(Document document)
  8. printXMLFormat(Document document)