Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import org.w3c.dom.Document;

import java.io.StringWriter;

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

public class Main {
    public static String DocumentToString(final Document doc) {
        try {
            StringWriter writer = new StringWriter();
            Result l_s = new StreamResult(writer);

            doc.normalize();

            TransformerFactory.newInstance().newTransformer().transform(new DOMSource(doc), l_s);

            return writer.toString();
        } catch (Exception e) {
            System.err.println(e);

            return null;
        }
    }
}