Java HTML Jsoup Element isEmptyElement(Node node)

Here you can find the source of isEmptyElement(Node node)

Description

is Empty Element

License

Apache License

Declaration

public static boolean isEmptyElement(Node node) 

Method Source Code

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

import org.jsoup.helper.StringUtil;
import org.jsoup.nodes.*;

public class Main {
    public static boolean isEmptyElement(Node node) {
        if (node == null) {
            return false;
        }//from ww  w .java2 s.  com
        if (node instanceof TextNode) {
            return StringUtil.isBlank(((TextNode) node).text());
        }
        if (!(node instanceof Element)) {
            return false;
        }
        boolean isEmptyTag = ((Element) node).tag().isEmpty();
        return !isEmptyTag && hasEmptyChidren(node);
    }

    public static boolean hasEmptyChidren(Node node) {
        if (node.childNodeSize() == 0)
            return true;
        for (Node n : node.childNodes()) {
            if (!(n instanceof TextNode)) {
                return false;
            }

            if (!StringUtil.isBlank(((TextNode) n).text())) {
                return false;
            }
        }
        return true;
    }
}

Related

  1. getTextFromNodeIfAvailable(Element doc)
  2. getTextFromNodeSelect(Element doc, String location, String locationValue)
  3. getTitle(Element el, String[] titles)
  4. getUserId(Element authorElement)
  5. isChildOf(Element child, Elements possibleParents)
  6. markAll(Elements tags)
  7. markChildren(Element tag, final String color)
  8. printNode(Element root)
  9. processCheck(Element ele, Element parent, String dict)