Here you can find the source of formatXml(String xml)
public static synchronized String formatXml(String xml)
//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 {//from w w w . j av a 2 s . c o m readableXformer.transform(new StreamSource(new StringReader(xml)), new StreamResult(output)); } catch (TransformerException e) { throw new RuntimeException("Failed to format XML", e); } return output.toString(); } }