Java XML Has Child hasElementChildren(Element elemNode)

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

Description

Returns true if the input element has element children.

License

Open Source License

Parameter

Parameter Description
elemNode a parameter

Declaration

public static boolean hasElementChildren(Element elemNode) 

Method Source Code

//package com.java2s;
/*--------------------------------------------------------------------------------
 Copyright (C) 2002, 2004 ISOGEN International

 http://www.isogen.com/*from  w w  w .j  a va  2 s  . c o m*/

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as published by
 the Free Software Foundation.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU Lesser General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

 --------------------------------------------------------------------------------*/

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

public class Main {
    /**
     * Returns true if the input element has element children.
     * 
     * @param elemNode
     * 
     */
    public static boolean hasElementChildren(Element elemNode) {
        NodeList nl = elemNode.getChildNodes();
        for (int i = 0; i < nl.getLength(); i++) {
            Node cand = nl.item(i);
            if (cand.getNodeType() == Node.ELEMENT_NODE) {
                return true;
            }
        }
        return false;
    }
}

Related

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