Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.*;

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.Element;

public class Main {
    public static String elementToString(Element ele) {
        try {
            StringWriter sw = new StringWriter();

            TransformerFactory tFactory = TransformerFactory.newInstance();
            Transformer transformer = tFactory.newTransformer();

            DOMSource source = new DOMSource(ele);
            StreamResult result = new StreamResult(sw);
            transformer.setOutputProperty("indent", "yes");
            transformer.transform(source, result);

            return sw.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}