Java Utililty Methods XML Node Print

List of utility methods to do XML Node Print

Description

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

Method

voidprettyPrint(Node root)
Can help debug Node objects from IIOMetadata#getAsTree(String) .
displayMetadata(root, 0);
voidprettyPrintLoop(Node node, StringBuilder string, String indentation)
pretty Print Loop
if (node == null) {
    return;
int type = node.getNodeType();
switch (type) {
case Node.DOCUMENT_NODE:
    string.append("\n");
    prettyPrintLoop(node.getChildNodes(), string, indentation + "\t");
...
StringprettyPrintNode(Node aNode, int indent)
pretty Print Node
StringBuilder str = new StringBuilder();
if (aNode.getNodeType() == Node.ELEMENT_NODE) {
    String uri = aNode.getNamespaceURI() == null ? "" : (" xmlns=\"" + aNode.getNamespaceURI() + "\"");
    StringBuilder attrs = new StringBuilder();
    NamedNodeMap attrss = aNode.getAttributes();
    for (int k = 0; k < attrss.getLength(); k++) {
        Node atr = attrss.item(k);
        attrs.append(" " + atr.getNodeName() + "=\"" + atr.getNodeValue() + "\"");
...
Stringprint(Node node)
Print a Node tree recursively.
if (node == null) {
    return null;
StringBuffer xml = new StringBuffer(100);
int type = node.getNodeType();
switch (type) {
case Node.ELEMENT_NODE: {
    xml.append('<');
...
voidprint(Node node)
Prints the specified node, recursively.
if (node == null) {
    return;
System.out.println("");
int type = node.getNodeType();
switch (type) {
case Node.DOCUMENT_NODE: {
    print(((Document) node).getDocumentElement());
...
voidprintArrayContent(Node[] t)
print Array Content
for (Node o : t) {
    System.out.println(o.getNodeName());
voidprintDifferences(Node node1, Node node2)
print Differences
if (node1.getNodeType() == Node.DOCUMENT_NODE)
    node1 = ((Document) node1).getDocumentElement();
if (node2.getNodeType() == Node.DOCUMENT_NODE)
    node2 = ((Document) node2).getDocumentElement();
if (node1.getNodeType() == Node.ELEMENT_NODE) {
    NamedNodeMap attrs1 = node1.getAttributes();
    NamedNodeMap attrs2 = node2.getAttributes();
    Node child1, child2;
...
voidprintDOM(Node node)
Prints the specified node, then prints all of its children.
int type = node.getNodeType();
switch (type) {
case Node.DOCUMENT_NODE: {
    System.out.println("<?xml version=\"1.0\" ?>");
    printDOM(((Document) node).getDocumentElement());
    break;
case Node.ELEMENT_NODE: {
...
voidprintDOM(Node node, String prefix)
Prints the specified node, then prints all of its children.
int type = node.getNodeType();
switch (type) {
case Node.DOCUMENT_NODE: {
    System.out.println("<?xml version=\"1.0\" ?>");
    printDOM(((Document) node).getDocumentElement(), prefix + " ");
    break;
case Node.ELEMENT_NODE: {
...
voidprintDOMTree(Node node, PrintStream out)
For debug purpose.
int type = node.getNodeType();
switch (type) {
case Node.DOCUMENT_NODE: {
    printDOMTree(((Document) node).getDocumentElement(), out);
    break;
case Node.ELEMENT_NODE: {
    out.print("<");
...