Java Utililty Methods XML Document Format

List of utility methods to do XML Document Format

Description

The list of methods to do XML Document Format are organized into topic(s).

Method

StringprintPrettyXML(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();
voidsaveDocumentToFormattedStream(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);
StringtoFormattedString(Document element)
Outputs a DOM Document node to a string with identation.
try {
    return serializeXML(element);
} catch (TransformerException e) {
    return "(no data)";