Java XML Has Child hasNonWhitespaceChildren(Element element)

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

Description

check, if the passed element node has non-whitespace children.

License

BSD License

Return

true, if any Element nodes are found, otherwise false

Declaration

public static boolean hasNonWhitespaceChildren(Element element) 

Method Source Code


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

import org.w3c.dom.*;

public class Main {
    /**
     * 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. hasElementChild(Node node)
  2. hasElementChildren(Element element)
  3. hasElementChildren(Element elemNode)
  4. hasElementChildren(Element elemNode)
  5. hasNamedChild(Element e, String name)
  6. hasOnlyTextChildNodes(final Node node)
  7. hasOnlyTextChildren( Node node)
  8. hasTextChildNodesOnly(Node node)