List of utility methods to do XML Element to String
String | toString(Element xml) to String try { Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); StreamResult result = new StreamResult(new StringWriter()); DOMSource source = new DOMSource(xml); transformer.transform(source, result); return result.getWriter().toString(); } catch (IllegalArgumentException | TransformerFactoryConfigurationError | TransformerException e) { ... |
String | toStringNoIndent(Element aElement) Converts an aElement to a String for printing without pretty printing.
String ret = "ERROR"; ByteArrayOutputStream theBuffer = new ByteArrayOutputStream(); try { TransformerFactory transFac = TransformerFactory.newInstance(); Transformer trans = transFac.newTransformer(); trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); trans.transform(new DOMSource(aElement), new StreamResult(theBuffer)); theBuffer.close(); ... |