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

voidprintElement(Node node, int level)
Prints elements of the specified node.
for (int i = 0; i < level; i++) {
    System.out.print("  ");
System.out.print("{" + node.getNamespaceURI() + "}");
System.out.println(node.getNodeName());
NamedNodeMap attrs = node.getAttributes();
if (attrs != null) {
    for (int i = 0; i < attrs.getLength(); i++) {
...
voidprintlnCommon(Node n)
println Common
System.out.print(" nodeName=\"" + n.getNodeName() + "\"");
String val = n.getNamespaceURI();
if (val != null) {
    System.out.print(" uri=\"" + val + "\"");
val = n.getPrefix();
if (val != null) {
    System.out.print(" pre=\"" + val + "\"");
...
voidprintNode(final String indent, final Node node)
print Node
System.out.print(indent + node.getNodeName());
System.out.print(": " + node.getNodeValue());
if (node.hasAttributes()) {
    System.out.print(": ");
    for (int i = 0; i < node.getAttributes().getLength(); i++) {
        if (i != 0) {
            System.out.print("# ");
        System.out.print(node.getAttributes().item(i));
System.out.println();
voidprintNode(Node aNode, int aLevel)
Prints a DOM Tree (recursive)
if (aNode == null) {
    return;
String spaces = "";
for (int i = 0; i < aLevel; i++) {
    spaces += "..";
System.out.println(spaces + "Name:  " + aNode.getNodeName());
...
StringprintNode(Node node)
print Node
StringBuffer sBuffer = new StringBuffer();
printNode(sBuffer, node);
return sBuffer.toString();
voidprintNode(Node node)
Provides a representation of XML to stdout.
int type = node.getNodeType();
switch (type) {
case Node.DOCUMENT_NODE: {
    System.out.println("<?xml version=\"1.0\" ?>");
    printNode(((Document) node).getDocumentElement());
    break;
case Node.ELEMENT_NODE: {
...
voidprintNode(Node node)
print Node
logger.debug("--> printNode() " + node.getNodeName());
logger.debug("prefix=" + node.getPrefix() + ", baseuri=" + node.getBaseURI() + ", nsuri="
        + node.getNamespaceURI() + ", value=" + node.getNodeValue());
if (node.getFirstChild() != null) {
    logger.debug("--> Child of " + node.getNodeName());
    printNode(node.getFirstChild());
    logger.debug("<-- Child of " + node.getNodeName());
if (node.getNextSibling() != null) {
    logger.debug("--> Sibling of " + node.getNodeName());
    printNode(node.getNextSibling());
    logger.debug("<-- Sibling of " + node.getNodeName());
logger.debug("<-- printNode() " + node.getNodeName());
voidprintNode(Node node)
print Node
System.out.println(node.getNodeValue());
voidprintNode(Node node, int level)
Prints information of the specified node.
if (node == null)
    return;
switch (node.getNodeType()) {
case Node.ATTRIBUTE_NODE:
    printAttribute(node, level);
    break;
case Node.TEXT_NODE:
    printTextNode(node, level);
...
voidprintNode(Node node, PrintStream out)
Print out the node in XML format
Document doc = new DocumentImpl();
Element topLevel = doc.createElement("xml");
doc.appendChild(topLevel);
topLevel.appendChild(doc.importNode(node, true));
OutputFormat format = new OutputFormat(doc);
format.setLineWidth(65);
format.setIndenting(true);
format.setIndent(2);
...