Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.io.ByteArrayOutputStream;
import java.io.StringReader;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;

import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

public class Main {
    private static Transformer readableXformer;

    public static synchronized String formatXml(String xml) {

        ByteArrayOutputStream output = new ByteArrayOutputStream();
        try {
            readableXformer.transform(new StreamSource(new StringReader(xml)), new StreamResult(output));
        } catch (TransformerException e) {
            throw new RuntimeException("Failed to format XML", e);
        }
        return output.toString();

    }
}