Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import java.io.ByteArrayOutputStream;
import org.w3c.dom.*;

import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;

public class Main {
    private static Transformer ourTransformer = null;

    /** Convert an xml Document object to a String */
    public static String convertDocumentToString(Document doc) {

        StreamResult sr = new StreamResult(new ByteArrayOutputStream());
        try {
            ourTransformer.transform(new DOMSource(doc), sr);
        } catch (TransformerException te) {
            System.out.println(te);
        }

        String docAsString = sr.getOutputStream().toString();
        return docAsString;
    }
}