XMLUtils { public static String prettyPrint(String xml) { LSParser parser = configurer.createLSParser(); configurer.setParserConfigParameter(parser, XmlConfigurer.VALIDATE_IF_SCHEMA, false); LSInput input = configurer.createLSInput(); try { Charset charset = getTargetCharset(xml); input.setByteStream(new ByteArrayInputStream(xml.trim().getBytes(charset))); input.setEncoding(charset.displayName()); } catch(UnsupportedEncodingException e) { throw new CitrusRuntimeException(e); } Document doc; try { doc = parser.parse(input); } catch (Exception e) { return xml; } return serialize(doc); } private  XMLUtils(); static void initialize(XmlConfigurer xmlConfigurer); static LSParser createLSParser(); static LSSerializer createLSSerializer(); static LSInput createLSInput(); static LSOutput createLSOutput(); static Node findNodeByName(Document doc, String pathExpression); static void stripWhitespaceNodes(Node element); static String getNodesPathName(Node node); static String serialize(Document doc); static String prettyPrint(String xml); static Map<String, String> lookupNamespaces(Node referenceNode); static Document parseMessagePayload(String messagePayload); static Charset getTargetCharset(Document doc); static String omitXmlDeclaration(String xml); static boolean hasXmlPayload(Message message);  }
@Test public void testPrettyPrint() throws IOException { String xml = "<testRequest><message>Hello</message></testRequest>"; int lines = 0; BufferedReader reader = null; String prettyprint = XMLUtils.prettyPrint(xml); try { reader = new BufferedReader(new StringReader(prettyprint)); while (reader.readLine() != null) { lines++; } } finally { if (reader != null) { reader.close(); } } Assert.assertTrue(prettyprint.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")); Assert.assertTrue(lines > 0); }