Java HTML Jsoup Element firstElement(final Element element, final String... tags)

Here you can find the source of firstElement(final Element element, final String... tags)

Description

first Element

License

Open Source License

Declaration

public static final Element firstElement(final Element element, final String... tags) 

Method Source Code

//package com.java2s;

import org.jsoup.nodes.Element;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;

public class Main {
    public static final Element firstElement(final Element element, final String... tags) {
        Element _element = element;
        for (String tag : tags)
            _element = firstChildByTag(_element, tag);
        return _element;
    }//from  w  w w.j a v a 2s  .  c o  m

    public static final Element firstChildByTag(final Element element, final String tag) {
        return Iterables.getFirst(childrenByTag(element, tag), null);
    }

    public static final Iterable<Element> childrenByTag(final Element element, final String tag) {
        return Iterables.filter(element.children(), new Predicate<Element>() {

            public final boolean apply(final Element _element) {
                return _element.tagName().equals(tag);
            }
        });
    }
}

Related

  1. findFirstByTag(Element element, String tag)
  2. findNextElementSibling(final Element startElement, final Predicate condition)
  3. findPreviousH2Element(Element h3)
  4. findPreviousHElement(Elements sequence, Element reference)
  5. findRootElement(Element element)
  6. getActiveJob(Element element)
  7. getAllNodes(Element element)
  8. getAuthorName(Element authorElement)
  9. getCodeSnippetCLT(Element codeElement, String content, String fqn, String api, String kind, String[] titles)