Transform XML Node - Android XML

Android examples for XML:XML Node

Description

Transform XML Node

Demo Code


//package com.java2s;
import org.w3c.dom.Node;
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.OutputStream;

public class Main {
    private static TransformerFactory transFactory = TransformerFactory
            .newInstance();/*  ww  w. j a v a2s.c  o  m*/

    public static void output(Node node, String encoding,
            OutputStream outputStream) throws TransformerException {
        Transformer transformer = transFactory.newTransformer();
        transformer.setOutputProperty("encoding", encoding);

        DOMSource source = new DOMSource();
        source.setNode(node);

        StreamResult result = new StreamResult();
        result.setOutputStream(outputStream);

        transformer.transform(source, result);
    }
}

Related Tutorials