Here you can find the source of printTree(NodeList childNodes, String padding, ByteArrayOutputStream byteArrayOS)
private static void printTree(NodeList childNodes, String padding, ByteArrayOutputStream byteArrayOS)
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import javax.xml.soap.Node; import org.w3c.dom.NodeList; public class Main { private static void printTree(NodeList childNodes, String padding, ByteArrayOutputStream byteArrayOS) { try {//from w w w. j a v a 2 s. c om NodeList nodes = childNodes; for (int i = 0; i < nodes.getLength(); i++) { Node node = (Node) nodes.item(i); String name = node.getNodeName(); if (node.hasChildNodes()) { byteArrayOS.write(('\n' + padding + "<" + name + ">") .getBytes());//'\n'+padding + printTree(node.getChildNodes(), padding + " ", byteArrayOS); byteArrayOS.write(("</" + name + ">").getBytes()); } else { byteArrayOS.write((new String((node.getNodeValue()))) .getBytes());//(new String((node.getTextContent()).getBytes("ISO-8859-1"), "UTF-8")).toString().getBytes()); } } } catch (Exception e) { } } }