is Empty XML Node - Java XML

Java examples for XML:DOM Node

Description

is Empty XML Node

Demo Code


//package com.java2s;

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

public class Main {

    public static boolean isEmptyNode(Node node) {
        NodeList nodeList = node.getChildNodes();
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node childNode = nodeList.item(i);
            if (!childNode.hasChildNodes()) {
                String value = childNode.getNodeValue();
                if (value != null && !value.isEmpty()) {
                    return false;
                }//w  ww .  j a va  2  s. c o m
            } else {
                if (!isEmptyNode(childNode)) {
                    return false;
                }
            }
        }
        return true;
    }
}

Related Tutorials