Java Utililty Methods XML DOM Print

List of utility methods to do XML DOM Print

Description

The list of methods to do XML DOM Print are organized into topic(s).

Method

voidprettyPrintDOM(Node node)
Serializes the specified node to stdout.
try {
    System.out.println();
    prettyPrintDOM(node, System.out);
    System.out.println("\n");
} catch (Exception e) {
    e.printStackTrace();
voidprettyPrintDOM(Node node, OutputStream stream)
Serializes the specified node to the given stream.
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.transform(new DOMSource(node), new StreamResult(stream));
voidprettyPrintDOMAsHTML(Node node, OutputStream stream)
pretty Print DOM As HTML
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.METHOD, "html");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.transform(new DOMSource(node), new StreamResult(stream));
voidprintDom(Node dom, OutputStream os)
Print a DOM tree to an output stream or if there is an exception while doing so, print the stack trace.
Transformer trans;
PrintWriter w = new PrintWriter(os);
try {
    TransformerFactory fact = TransformerFactory.newInstance();
    trans = fact.newTransformer();
    trans.transform(new DOMSource(dom), new StreamResult(new OutputStreamWriter(os)));
} catch (TransformerException e) {
    w.println("An error ocurred while transforming the given DOM:");
...
voidprintDOM(Node node, OutputStream out, String encoding)
print DOM
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer;
transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.ENCODING, encoding);
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
...
voidprintDOM(Node root, OutputStream os)
Prints DOM to output stream.
identityTransform(root, new StreamResult(os));
voidprintDOMTree(Node node, PrintWriter out, String docType, String copyright)
Debugging method for printing out the DOM Tree Prints the specified node, recursively.
try {
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.setOutputProperty(OutputKeys.METHOD, "xml");
    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    out.print("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
    if (copyright != null) {
...
StringprintTreeDOM(final Element samlToken, final boolean isIndent)
Prints the tree DOM.
final TransformerFactory transfac = TransformerFactory.newInstance();
final Transformer trans = transfac.newTransformer();
trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
trans.setOutputProperty(OutputKeys.INDENT, String.valueOf(isIndent));
final StringWriter stringWriter = new StringWriter();
final StreamResult result = new StreamResult(stringWriter);
final DOMSource source = new DOMSource(samlToken);
trans.transform(source, result);
...