Android XML Element Child Check hasChildElements(Element element)

Here you can find the source of hasChildElements(Element element)

Description

Indicates whether element has any child element.

License

LGPL

Parameter

Parameter Description
element the namespace to analyze.

Return

true if element has any child element otherwise false.

Declaration

public static boolean hasChildElements(Element element) 

Method Source Code

//package com.java2s;
/*//  ww w.ja  v a2 s .  c  o m
 * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

import org.w3c.dom.*;

public class Main {
    /**
     * Indicates whether element has any child element.
     *
     * @param element the namespace to analyze.
     * @return true if element has any child element otherwise false.
     */
    public static boolean hasChildElements(Element element) {
        NodeList childNodes = element.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node node = childNodes.item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                return true;
            }
        }
        return false;
    }
}

Related

  1. hasChildren(Element e)