/** * Add a form control element to this form. * @param element form control to add * @return this form element, for chaining */ public FormElement addElement(Element element) { elements.add(element); return this; }
public void head(Node node, int depth) { if (node instanceof Element) { Element el = (Element) node; if (eval.matches(root, el)) elements.add(el); } }
/** * Creates a deep copy of these elements. * @return a deep copy */ @Override public Elements clone() { Elements clone = new Elements(size()); for(Element e : this) clone.add(e.clone()); return clone; }
static Elements filterOut(Collection<Element> elements, Collection<Element> outs) { Elements output = new Elements(); for (Element el : elements) { boolean found = false; for (Element out : outs) { if (el.equals(out)) { found = true; break; } } if (!found) output.add(el); } return output; }
private static void accumulateParents(Element el, Elements parents) { Element parent = el.parent(); if (parent != null && !parent.tagName().equals("#root")) { parents.add(parent); accumulateParents(parent, parents); } }
private Elements siblings(String query, boolean next, boolean all) { Elements els = new Elements(); Evaluator eval = query != null? QueryParser.parse(query) : null; for (Element e : this) { do { Element sib = next ? e.nextElementSibling() : e.previousElementSibling(); if (sib == null) break; if (eval == null) els.add(sib); else if (sib.is(eval)) els.add(sib); e = sib; } while (all); } return els; }
/** * Get sibling elements. If the element has no sibling elements, returns an empty list. An element is not a sibling * of itself, so will not be included in the returned list. * @return sibling elements */ public Elements siblingElements() { if (parentNode == null) return new Elements(0); List<Element> elements = parent().childElementsList(); Elements siblings = new Elements(elements.size() - 1); for (Element el: elements) if (el != this) siblings.add(el); return siblings; }
contextChain.add(0, context); for (Element parent: contextChain) { if (parent instanceof FormElement) {
descriptions.add(context.readDesign(child)); } else { content.add(child);
Elements divs = document.select("div"); Elements innerMostDivs = new Elements(); for (Element div : divs) { if (div.select(">div").isEmpty()) { innerMostDivs.add(div); } } // ...
Elements fooElements = Jsoup .parse(html) .body().select(".foo"); Elements elements = new Elements() for(Element el : fooElements) { elements.add(el.select(".bar").first()); }
String input = "<div>a</div><p>b</p><strong>c</strong>"; Document doc = Jsoup.parse(input); Elements elements = doc.select("p ~ *"); Elements group = new Elements(); group.add(elements.first().previousElementSibling()); for( Element element : elements ) { group.add(element); } // You can work with 'group' too String output = group.toString();
private Elements getImagesToAttach(Document doc, ImageResource image) { Elements imgs = doc.select(MessageFormat.format(IMG_SELECTOR, image.getPath())); Elements found = new Elements(); for (Element img : imgs) { // skip images that have skip-attach attribute if (isInlineModeAllowed(img, ATTACH)) { found.add(img); } } return found; }
Element body = doc.select("body").first(); Elements bodyChildren = new Elements(); for (Element e : body.children()) { bodyChildren.add(e); }
public static Elements followingSibling(Element el){ Elements rs = new Elements(); Element tmp = el.nextElementSibling(); while (tmp!=null){ rs.add(tmp); tmp = tmp.nextElementSibling(); } if (rs.size() > 0){ return rs; } return null; }
Document doc = Jsoup.parse(h); Element firstDiv = doc.select("div.clear").first(); Elements news = new Elements(); Element item = firstDiv.nextElementSibling(); while (item != null && !(item.tagName().equals("div") && item.className().equals("clear"))) { news.add(item); item = item.nextElementSibling(); } System.out.println(String.format("Found %s items", news.size())); for (Element element : news) { System.out.println(element.text()); }
public static Elements followingSibling(Element el){ Elements rs = new Elements(); Element tmp = el.nextElementSibling(); while (tmp!=null){ rs.add(tmp); tmp = tmp.nextElementSibling(); } if (rs.size() > 0){ return rs; } return null; }
public static void main(String[] args) throws Exception { String html = new String(Files.readAllBytes(Paths.get("input.html"))); Document doc = Jsoup.parse(html); Elements section = new Elements(); Element sibling = doc.getElementById("dd_start").nextElementSibling(); do { section.add(sibling); sibling = sibling.nextElementSibling(); } while(!sibling.id().equals("dd_end")); System.out.println(section); }
@Override public XElements evaluate(Element element) { Elements elements; if (evaluator != null) { elements = Collector.collect(evaluator, element); } else { elements = new Elements(); elements.add(element); } return new DefaultXElements(elements, elementOperator); }
@Override public XElements evaluate(Element element) { Elements elements; if (evaluator != null) { elements = Collector.collect(evaluator, element); } else { elements = new Elements(); elements.add(element); } return new DefaultXElements(elements, elementOperator); }