Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import java.io.ByteArrayOutputStream;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Node;

public class Main {
    public static String nodeAsString(Node node) {
        String nodeStr = "";
        TransformerFactory tff = TransformerFactory.newInstance();
        try {
            Transformer tf = tff.newTransformer();
            tf.setOutputProperty("encoding", "UTF-8");

            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            tf.transform(new DOMSource(node), new StreamResult(bos));
            return bos.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return nodeStr;
    }
}