Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/**
 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
 */

import java.io.ByteArrayOutputStream;

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;

public class Main {
    public static String transformDOMToString(DOMSource source) {
        try {
            // Use a Transformer for output
            TransformerFactory tFactory = TransformerFactory.newInstance();
            Transformer transformer = tFactory.newTransformer();
            ByteArrayOutputStream sos = new ByteArrayOutputStream();
            StreamResult result = new StreamResult(sos);
            transformer.transform(source, result);
            return sos.toString();
        } catch (TransformerException e) {
            throw new IllegalArgumentException(e);
        }

    }
}