List of utility methods to do XML Document Format
String | printPrettyXML(Document doc) print Pretty XML Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty("indent", "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "3"); StringWriter output = new StringWriter(); transformer.transform(new DOMSource(doc), new StreamResult(output)); return output.toString(); |
void | saveDocumentToFormattedStream(Document doc, OutputStream outputStream) Save the given document to an output stream. Source source = new DOMSource(doc); Result result = new StreamResult(outputStream); Transformer transformer = createTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "4"); transformer.transform(source, result); |
String | toFormattedString(Document element) Outputs a DOM Document node to a string with identation. try { return serializeXML(element); } catch (TransformerException e) { return "(no data)"; |