@ Deprecated public static String formatXml ( String xml ) { try { Transformer serializer = SAXTransformerFactory . newInstance ( ) . newTransformer ( ) ; serializer . setOutputProperty ( OutputKeys . INDENT , "yes" ) ; serializer . setOutputProperty ( "{http://xml.apache.org/xslt}indent-amount" , "2" ) ; Source xmlSource = new SAXSource ( new InputSource ( new ByteArrayInputStream ( xml . getBytes ( ) ) ) ) ; StreamResult res = new StreamResult ( new ByteArrayOutputStream ( ) ) ; serializer . transform ( xmlSource , res ) ; return new String ( ( ( ByteArrayOutputStream ) res . getOutputStream ( ) ) . toByteArray ( ) ) ; } catch ( Exception e ) { return xml ; } }
Unnecessary as the stax driver custom anon as static definition is embedding the indentation .