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

voidprintNode(Node node, StringWriter sw)
Write a node to the current output buffer
if (node.getNodeType() == Node.TEXT_NODE) {
    String content = node.getTextContent();
    if (content.contains("&"))
        content = content.replace("&", "&");
    sw.write(content);
} else if (node.getNodeType() == Node.ELEMENT_NODE) {
    printElementStart((Element) node, sw);
    printElementBody((Element) node, sw);
...
voidprintNodeBasics(Node node)
Prints a given Node

For debugging purpose only

if (node == null)
    System.out.println(" Null node");
    return;
System.out.println(" Node[Namespace URI=" + node.getNamespaceURI() + " localname=" +
        node.getLocalName() + " name=" +
        node.getNodeName() + " type=" +
...
voidprintNodeIterator(NodeIterator iterator)
print Node Iterator
Node n;
while ((n = iterator.nextNode()) != null) {
    System.out.println("Node:" + n.getNodeValue());
voidprintNodes(Node node, int level)
Method to print nodes of the DOM
level++;
System.out.println(node);
for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
    printNodes(child, level);
return;
voidprintNodeType(Node node, int ident)
prints the type of the input node
System.out.print("Node: " + node.getNodeName() + " ");
switch (node.getNodeType()) {
case Node.DOCUMENT_NODE:
    System.out.println("Document Node");
    break;
case Node.ELEMENT_NODE:
    System.out.println("Element Node");
    for (int j = 0; j < 2 * ident; j++)
...
voidprintToTerminal(Node n, String indent, boolean descend)
print To Terminal
if (n != null) {
    System.out.println(indent + "Name: " + n.getNodeName());
    System.out.println(indent + "NS  : " + n.getNamespaceURI());
    System.out.println(indent + "txt : " + n.getTextContent());
    System.out.println(indent + "Type: " + n.getNodeType());
    System.out.println(indent + "Val : [" + n.getNodeValue() + "]");
    if (n.hasAttributes())
        printAttributesCompact(n.getAttributes(), indent, descend);
...
voidprintTree(Node node, int ident)
prints the document tree
if (node == null)
    return;
NodeList children;
System.out.print("Node: " + node.getNodeName() + " ");
switch (node.getNodeType()) {
case Node.DOCUMENT_NODE:
    System.out.println("Document Node");
    break;
...
voidprintTree(Node root, int level)
print a text representation of the dom hierarchy.
NodeList l = root.getChildNodes();
for (int i = 0; i < level; i++)
    System.out.print("    ");
NamedNodeMap attribMap = root.getAttributes();
String attribs = getAttributeList(attribMap);
System.out.println("Node: <" + root.getNodeName() + ">  " + attribs);
for (int i = 0; i < l.getLength(); i++) {
    printTree(l.item(i), level + 1);
...