debug Print Children XML Node - Java XML

Java examples for XML:XML Element Child

Description

debug Print Children XML Node

Demo Code


//package com.java2s;

import org.w3c.dom.Element;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    public static void debugPrintChildren(Node node) {
        NodeList nl = node.getChildNodes();
        System.out.println("-------------------");
        for (int i = 0; i < nl.getLength(); i++) {
            System.out.println(nl.item(i).toString());
            if (nl.item(i) instanceof Element) {
                System.out.println(((Element) nl.item(i))
                        .getAttribute("className"));
                System.out.println(((Element) nl.item(i)).getTagName());
            }/*  w ww  .ja  v  a  2 s  . c o m*/
            System.out.println("---");
        }

    }
}

Related Tutorials