Java Utililty Methods HTML Jsoup Element

List of utility methods to do HTML Jsoup Element

Description

The list of methods to do HTML Jsoup Element are organized into topic(s).

Method

booleanisEmptyElement(Node node)
is Empty Element
if (node == null) {
    return false;
if (node instanceof TextNode) {
    return StringUtil.isBlank(((TextNode) node).text());
if (!(node instanceof Element)) {
    return false;
...
voidmarkAll(Elements tags)
mark All
markAll(tags, defaultColor);
voidmarkChildren(Element tag, final String color)
mark Children
tag.traverse(new NodeVisitor() {
    @Override
    public void head(Node node, int i) {
        if (node instanceof Element) {
            Element tag = (Element) node;
            mark(tag, color);
    @Override
    public void tail(Node node, int i) {
});
StringprintNode(Element root)
print Node
return printNode(root, 0);
StringprocessCheck(Element ele, Element parent, String dict)
process Check
StringBuilder builder = new StringBuilder();
builder.append("<input name=\"").append(ele.attr("name"));
builder.append("\" id=\"").append(ele.attr("id"));
builder.append("\" style=\"").append(ele.attr("style"));
builder.append("\" value=\"");
builder.append("\" type=\"check\"/>");
builder.append("");
return builder.toString();
...
ElementrandomElement()
random Element
return Jsoup.parse("<p>text</p>");
voidreplaceHtml(Node element)
replace Html
List<Node> elements = element.childNodes();
Pattern compile = Pattern.compile("(?:https?|ftps?)://[\\w/%.-][/\\??\\w=?\\w?/%.-]?[/\\?&\\w=?\\w?/%.-]*");
for (int i = elements.size() - 1; i >= 0; i--) {
    Node node = elements.get(i);
    if (node instanceof TextNode) {
        String value = ((TextNode) node).text();
        Matcher matcher = compile.matcher(value);
        if (matcher.find()) {
...
intsameTagElNums(Element e)
same Tag El Nums
Elements els = e.parent().getElementsByTag(e.tagName());
return els.size();
voidsetAttribute(Element e, String key, String value)
Set an attribute on an element (in the data-baleen namespace)
e.attr(attributeKey(key), value);
voidstripAttribute(Element body, String attribute)
strip Attribute
Elements elements = body.getElementsByAttribute(attribute);
for (Element e : elements) {
    e.removeAttr(attribute);