Java XML String Transform writeXml(OutputStream os, Node node, String encoding)

Here you can find the source of writeXml(OutputStream os, Node node, String encoding)

Description

write Xml

License

Open Source License

Declaration

public static void writeXml(OutputStream os, Node node, String encoding) throws TransformerException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.Node;

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 java.io.*;

public class Main {

    public static void writeXml(OutputStream os, Node node, String encoding) throws TransformerException {
        TransformerFactory transFactory = TransformerFactory.newInstance();
        Transformer transformer = transFactory.newTransformer();
        transformer.setOutputProperty("indent", "yes");
        transformer.setOutputProperty(OutputKeys.ENCODING, encoding);

        DOMSource source = new DOMSource();
        source.setNode(node);//  www.  jav a  2s .  c o  m
        StreamResult result = new StreamResult();
        result.setOutputStream(os);

        transformer.transform(source, result);
    }
}

Related

  1. writeNodeSubtreeXMLString(final Node node, final Writer writer)
  2. writePropToString(Properties props)
  3. writeResultToFile(final StreamResult result, final String path)
  4. writeToFile(String xmlContent, String path)
  5. writeXML(Node node, String dtdFilename, String outputFileName)
  6. writeXmlFile(Element doc, String filename)
  7. writeXmlResult(String xml, Writer w)
  8. xslString(final String xmlFile, final InputStream xslStream)