Java Code Examples for org.jsoup.nodes.Element#parents()

The following examples show how to use org.jsoup.nodes.Element#parents() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Rgaa22Rule09081.java    From Asqatasun with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Checks recursively whether an element has a parent with a lang attribute
 *
 * @param el
 * @return whether the element passed as argument has a parent with a lang
 * attribute
 */
private boolean isElementHasParentWithLang(Element el) {
    for (Element pel : el.parents()) {
        if (!pel.nodeName().equals(HTML_ELEMENT)
                && (pel.hasAttr(LANG_ATTR)
                || pel.hasAttr(XML_LANG_ATTR))) {
            return true;
        }
    }
    return false;
}
 
Example 2
Source File: StructuralAnnotations.java    From baleen with Apache License 2.0 5 votes vote down vote up
private int findRowIndexOfCell(final Element element) {
  for (final Element e : element.parents()) {
    if (e.tagName().equalsIgnoreCase("tr")) {
      return findRowIndexOfRow(e);
    }
  }
  return -1;
}
 
Example 3
Source File: JsoupParserIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void examplesTraversing() {
    Elements sections = doc.select("section");

    Element firstSection = sections.first();
    Element lastSection = sections.last();
    Element secondSection = sections.get(2);
    Elements allParents = firstSection.parents();
    Element parent = firstSection.parent();
    Elements children = firstSection.children();
    Elements siblings = firstSection.siblingElements();

    sections.forEach(el -> System.out.println("section: " + el));
}
 
Example 4
Source File: AxisSelector.java    From CrawlerForReader with Apache License 2.0 2 votes vote down vote up
/**
 * 全部祖先节点 父亲,爷爷 , 爷爷的父亲...
 *
 * @param e
 * @return
 */
public Elements ancestor(Element e) {
    return e.parents();
}
 
Example 5
Source File: AxisSelector.java    From CrawlerForReader with Apache License 2.0 2 votes vote down vote up
/**
 * 全部祖先节点和自身节点
 *
 * @param e
 * @return
 */
public Elements ancestorOrSelf(Element e) {
    Elements rs = e.parents();
    rs.add(e);
    return rs;
}