Java XML Has Child hasChildElements(Element element)

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

Description

True if element has children elements

License

Apache License

Parameter

Parameter Description
element element that we wanted to know if it has children

Return

true if element has children elements

Declaration


public static boolean hasChildElements(Element element) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.NodeList;
import org.w3c.dom.Element;

import org.w3c.dom.Node;

public class Main {
    /** True if element has children elements
    @param element element that we wanted to know if it has children 
    @return true if element has children elements
    *///w  w w.j  av a 2s.c  o m

    public static boolean hasChildElements(Element element) {
        NodeList childs = element.getChildNodes();

        for (int i = 0; i < childs.getLength(); i++) {
            Node node = childs.item(i);
            if (Node.ELEMENT_NODE == node.getNodeType()) {
                return true;
            }
        }
        return false;
    }
}

Related

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