本文整理了Java中org.jsoup.nodes.Element.parents()
方法的一些代码示例,展示了Element.parents()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.parents()
方法的具体详情如下:
包路径:org.jsoup.nodes.Element
类名称:Element
方法名:parents
[英]Get this element's parent and ancestors, up to the document root.
[中]获取此元素的父元素和祖先元素,直至文档根。
代码示例来源:origin: org.jsoup/jsoup
/**
* Get all of the parents and ancestor elements of the matched elements.
* @return all of the parents and ancestor elements of the matched elements
*/
public Elements parents() {
HashSet<Element> combo = new LinkedHashSet<>();
for (Element e: this) {
combo.addAll(e.parents());
}
return new Elements(combo);
}
代码示例来源:origin: org.jsoup/jsoup
Elements contextChain = context.parents();
contextChain.add(0, context);
for (Element parent: contextChain) {
代码示例来源:origin: spring-projects/spring-roo
topMostElementLevel = element.parents().size();
topMostElements.add(element);
continue;
if (element.parents().size() < topMostElementLevel) {
topMostElementLevel = element.parents().size();
topMostElements.clear();
topMostElements.add(element);
if (element.parents().size() == topMostElementLevel) {
代码示例来源:origin: astamuse/asta4d
public Elements parents() {
return originElement.parents();
}
代码示例来源:origin: perfectsense/dari
protected static Element closestItemScope(Element element) {
for (Element p : element.parents()) {
if (p.hasAttr("itemscope")) {
return p;
}
}
return null;
}
代码示例来源:origin: andriusvelykis/reflow-maven-skin
/**
* Filters the list of elements to only contain parent elements. This is to avoid both parent
* and child being in the list of elements.
*
* @param elements
* @return
*/
private static List<Element> filterParents(List<Element> elements) {
List<Element> filtered = new ArrayList<Element>();
for (Element element : elements) {
// get the intersection of parents and selected elements
List<Element> parentsInter = element.parents();
parentsInter.retainAll(elements);
if (parentsInter.isEmpty()) {
// no intersection - element's parents are not in the selected list
filtered.add(element);
}
}
return filtered;
}
代码示例来源:origin: lt.velykis.maven.skins/reflow-velocity-tools
/**
* Filters the list of elements to only contain parent elements. This is to avoid both parent
* and child being in the list of elements.
*
* @param elements
* @return
*/
private static List<Element> filterParents(List<Element> elements) {
List<Element> filtered = new ArrayList<Element>();
for (Element element : elements) {
// get the intersection of parents and selected elements
List<Element> parentsInter = element.parents();
parentsInter.retainAll(elements);
if (parentsInter.isEmpty()) {
// no intersection - element's parents are not in the selected list
filtered.add(element);
}
}
return filtered;
}
代码示例来源:origin: mangstadt/ez-vcard
/**
* Determines whether the given element is a child of one of the given
* parent elements.
* @param child the child element
* @param possibleParents the possible parents
* @return true if it is a child, false if not
*/
public static boolean isChildOf(Element child, Elements possibleParents) {
for (Element parent : child.parents()) {
if (possibleParents.contains(parent)) {
return true;
}
}
return false;
}
代码示例来源:origin: stackoverflow.com
List<Element> keepList = new ArrayList<>();
Elements els = doc.select(".cellRight");
for (Element el : els){
boolean keep = true;
for (Element parentEl : el.parents()){
if (parentEl.hasClass("cellRight")){
//parent has class as well -> discard!
keep = false;
break;
}
}
if (keep){
keepList.add(el);
}
}
//keepList now contains inner most elements with your class
代码示例来源:origin: cn.wanghaomiao/JsoupXpath
@Override
public XValue apply(Elements context) {
List<Element> total = new LinkedList<>();
for (Element el:context){
total.addAll(el.parents());
}
return XValue.create(new Elements(total));
}
}
代码示例来源:origin: stackoverflow.com
for (Element elem : document.select(".singolo-contenuto a")) {
if(elem.parents().hasClass("list_attachments")) continue;
String href = elem.attr("href");
String text = elem.text();
elem.replaceWith(new TextNode(href + " " + text, ""));
}
String result = document.select(".singolo-contenuto").text();
代码示例来源:origin: cn.wanghaomiao/JsoupXpath
@Override
public XValue apply(Elements context) {
List<Element> total = new LinkedList<>();
for (Element el:context){
total.addAll(el.parents());
//include self
total.add(el);
}
return XValue.create(new Elements(total));
}
}
代码示例来源:origin: uk.gov.dstl.baleen/baleen-collectionreaders
private int findRowIndexOfCell(final Element element) {
for (final Element e : element.parents()) {
if (e.tagName().equalsIgnoreCase("tr")) {
return findRowIndexOfRow(e);
}
}
return -1;
}
代码示例来源:origin: dstl/baleen
private int findRowIndexOfCell(final Element element) {
for (final Element e : element.parents()) {
if (e.tagName().equalsIgnoreCase("tr")) {
return findRowIndexOfRow(e);
}
}
return -1;
}
代码示例来源:origin: zhegexiaohuozi/JsoupXpath
@Override
public XValue apply(Elements context) {
Set<Element> total = new HashSet<>();
Elements ancestor = new Elements();
for (Element el:context){
total.addAll(el.parents());
}
ancestor.addAll(total);
return XValue.create(ancestor);
}
}
代码示例来源:origin: zhegexiaohuozi/JsoupXpath
@Override
public XValue apply(Elements context) {
Set<Element> total = new HashSet<>();
Elements ancestor = new Elements();
for (Element el:context){
total.addAll(el.parents());
//include self
total.add(el);
}
ancestor.addAll(total);
return XValue.create(ancestor);
}
}
代码示例来源:origin: basis-technology-corp/Java-readability
private void handleDoubleBr() {
Elements doubleBrs = document.select("br + br");
for (Element br : doubleBrs) {
// we hope that there's a 'p' up there....
Elements parents = br.parents();
Element parent = null;
for (Element aparent : parents) {
if (aparent.tag().getName().equals("p")) {
parent = aparent;
break;
}
}
if (parent == null) {
parent = br.parent();
parent.wrap("<p></p>");
}
// now it's safe to make the change.
String inner = parent.html();
inner = Patterns.REPLACE_BRS.matcher(inner).replaceAll("</p><p>");
parent.html(inner);
}
}
代码示例来源:origin: zhegexiaohuozi/JsoupXpath
@Override
public XValue apply(Elements context) {
Elements following = new Elements();
Set<Element> total = new HashSet<>();
for (Element el:context){
Elements p = el.parents();
for (Element pe: p){
Elements fs = CommonUtil.followingSibling(pe);
if (fs==null){
continue;
}
total.addAll(fs);
}
Elements fs = CommonUtil.followingSibling(el);
if (fs==null){
continue;
}
total.addAll(fs);
}
following.addAll(total);
return XValue.create(following);
}
}
代码示例来源:origin: cn.wanghaomiao/JsoupXpath
/**
* @param context
* @return res
*/
@Override
public XValue apply(Elements context) {
Elements preceding = new Elements();
List<Element> total = new LinkedList<>();
for (Element el:context){
Elements p = el.parents();
for (Element pe: p){
Elements ps = CommonUtil.precedingSibling(pe);
if (ps==null){
continue;
}
total.addAll(ps);
}
Elements ps = CommonUtil.precedingSibling(el);
if (ps == null){
continue;
}
total.addAll(ps);
}
preceding.addAll(total);
return XValue.create(preceding);
}
}
代码示例来源:origin: cn.wanghaomiao/JsoupXpath
@Override
public XValue apply(Elements context) {
List<Element> total = new LinkedList<>();
for (Element el:context){
Elements p = el.parents();
for (Element pe: p){
Elements fs = CommonUtil.followingSibling(pe);
if (fs==null){
continue;
}
for(Element pse:fs){
//include pse
total.addAll(pse.getAllElements());
}
}
Elements fs = CommonUtil.followingSibling(el);
if (fs==null){
continue;
}
for (Element se:fs){
total.addAll(se.getAllElements());
}
}
return XValue.create(new Elements(total));
}
}
内容来源于网络,如有侵权,请联系作者删除!