Java HTML Jsoup Element stripEmptyDivs(Element body)

Here you can find the source of stripEmptyDivs(Element body)

Description

strip Empty Divs

License

Open Source License

Declaration

private static void stripEmptyDivs(Element body) 

Method Source Code

//package com.java2s;

import org.jsoup.nodes.Element;

import org.jsoup.select.Elements;

public class Main {
    private static void stripEmptyDivs(Element body) {
        stripEmptyTag(body, "div");
    }/*w w  w. j  a v a  2s  . c om*/

    private static void stripEmptyTag(Element body, String tag) {
        Elements elements = body.select(tag);
        for (Element e : elements) {
            if ((e.html() == null || e.html().trim().length() == 0)
                    && (e.text() == null || e.text().trim().length() == 0)) {
                e.remove();
            }
        }
    }
}

Related

  1. randomElement()
  2. replaceHtml(Node element)
  3. sameTagElNums(Element e)
  4. setAttribute(Element e, String key, String value)
  5. stripAttribute(Element body, String attribute)
  6. stripStyles(Element body)
  7. updateData(Element element, String data)