Here you can find the source of formatXML(byte[] xmlData, int indent)
public static String formatXML(byte[] xmlData, int indent) throws TransformerException
//package com.java2s; import java.io.ByteArrayInputStream; import java.io.StringWriter; import javax.xml.transform.OutputKeys; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; public class Main { public static String formatXML(byte[] xmlData, int indent) throws TransformerException { Source xmlInput = new StreamSource(new ByteArrayInputStream(xmlData)); StreamResult xmlOutput = new StreamResult(new StringWriter()); TransformerFactory transformerFactory = TransformerFactory.newInstance(); transformerFactory.setAttribute("indent-number", indent); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.transform(xmlInput, xmlOutput); return xmlOutput.getWriter().toString(); }// www . ja v a 2 s. c o m }