Java XML Has Child hasChildElements(Element element)

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

Description

Determine whether an element has any child elements.

License

Open Source License

Parameter

Parameter Description
element the element to check.

Return

true if the element has child elements; false otherwise.

Declaration

public static boolean hasChildElements(Element element) 

Method Source Code

//package com.java2s;
/*---------------------------------------------------------------
*  Copyright 2005 by the Radiological Society of North America
*
*  This source software is released under the terms of the
*  RSNA Public License (http://mirc.rsna.org/rsnapubliclicense)
*----------------------------------------------------------------*/

import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class Main {
    /**/*from   w ww.  j a v a  2  s. c  o m*/
     * Determine whether an element has any child elements.
     * @param element the element to check.
     * @return true if the element has child elements; false otherwise.
     */
    public static boolean hasChildElements(Element element) {
        Node child = element.getFirstChild();
        while (child != null) {
            if (child.getNodeType() == Node.ELEMENT_NODE)
                return true;
            child = child.getNextSibling();
        }
        return false;
    }
}

Related

  1. hasChildElement(Element element, String name)
  2. hasChildElement(NodeList list)
  3. hasChildElement(TreeWalker walker)
  4. hasChildElementNodes(@Nonnull final Node aStartNode)
  5. hasChildElements(Element element)
  6. hasChildElements(Element element)
  7. hasChildElements(Node node)
  8. hasChildElements(Node node)
  9. hasChildElements(Node node)