Java XML Has Child 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;
/*//from  w  w w .  j  av  a 2 s .c  om
 * 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. hasChildElement(NodeList list)
  2. hasChildElement(TreeWalker walker)
  3. hasChildElementNodes(@Nonnull final Node aStartNode)
  4. hasChildElements(Element element)
  5. hasChildElements(Element element)
  6. hasChildElements(Node node)
  7. hasChildElements(Node node)
  8. hasChildElements(Node node)
  9. hasChildElements(Node node)