Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.StringWriter;

import javax.xml.transform.Transformer;

import javax.xml.transform.TransformerException;

import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;

public class Main {
    private static Transformer _transformer = null;

    public static String documentToString(Document doc) {
        StreamResult sr = new StreamResult(new StringWriter());
        DOMSource source = new DOMSource(doc);
        try {
            _transformer.transform(source, sr);
        } catch (TransformerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return sr.getWriter().toString();
    }
}