Java XML Has Child hasElementChildren(Element element)

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

Description

just the same as hasNonWhitespaceChildren, but seen from a different perspective ;)

License

BSD License

Parameter

Parameter Description
element a parameter

Return

true, if any Element nodes are found, otherwise false

Declaration

public static boolean hasElementChildren(Element element) 

Method Source Code


//package com.java2s;
/*/*w w  w .  ja  va  2s. c  o  m*/
 * Copyright (c) 2012. betterFORM Project - http://www.betterform.de
 * Licensed under the terms of BSD License
 */

import org.w3c.dom.*;

public class Main {
    /**
     * just the same as hasNonWhitespaceChildren, but seen from a different perspective ;)
     *
     * @param element
     * @return true, if any Element nodes are found, otherwise false
     */
    public static boolean hasElementChildren(Element element) {
        return hasNonWhitespaceChildren(element);
    }

    /**
     * check, if the passed element node has non-whitespace children.
     *
     * @return true, if any Element nodes are found, otherwise false
     */
    public static boolean hasNonWhitespaceChildren(Element element) {
        if (element.hasChildNodes()) {
            NodeList children = element.getChildNodes();
            int len = children.getLength();
            Node n = null;

            for (int i = 0; i < len; i++) {
                n = children.item(i);

                if (n.getNodeType() == Node.ELEMENT_NODE) {
                    return true;
                }
            }

            return false;
        } else {
            return false;
        }
    }
}

Related

  1. hasChildren(Element element, String childName)
  2. hasChildren(final Element el)
  3. hasChildren(final Node node)
  4. hasElementChild(Node node)
  5. hasElementChild(Node node)
  6. hasElementChildren(Element elemNode)
  7. hasElementChildren(Element elemNode)
  8. hasNamedChild(Element e, String name)
  9. hasNonWhitespaceChildren(Element element)