|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jsoup.select.Elements
public class Elements
A list of Elements
, with methods that act on every element in the list.
Element.select(String)
method.
Constructor Summary | |
---|---|
Elements()
|
|
Elements(Collection<Element> elements)
|
|
Elements(Element... elements)
|
|
Elements(int initialCapacity)
|
|
Elements(List<Element> elements)
|
Method Summary | ||
---|---|---|
boolean |
add(Element element)
|
|
void |
add(int index,
Element element)
|
|
boolean |
addAll(Collection<? extends Element> c)
|
|
boolean |
addAll(int index,
Collection<? extends Element> c)
|
|
Elements |
addClass(String className)
Add the class name to every matched element's class attribute. |
|
Elements |
after(String html)
Insert the supplied HTML after each matched element's outer HTML. |
|
Elements |
append(String html)
Add the supplied HTML to the end of each matched element's inner HTML. |
|
String |
attr(String attributeKey)
Get an attribute value from the first matched element that has the attribute. |
|
Elements |
attr(String attributeKey,
String attributeValue)
Set an attribute on all matched elements. |
|
Elements |
before(String html)
Insert the supplied HTML before each matched element's outer HTML. |
|
void |
clear()
|
|
Elements |
clone()
|
|
boolean |
contains(Object o)
|
|
boolean |
containsAll(Collection<?> c)
|
|
Elements |
empty()
Empty (remove all child nodes from) each matched element. |
|
Elements |
eq(int index)
Get the nth matched element as an Elements object. |
|
boolean |
equals(Object o)
|
|
Element |
first()
Get the first matched element. |
|
Element |
get(int index)
|
|
boolean |
hasAttr(String attributeKey)
Checks if any of the matched elements have this attribute set. |
|
boolean |
hasClass(String className)
Determine if any of the matched elements have this class name set in their class attribute. |
|
int |
hashCode()
|
|
boolean |
hasText()
|
|
String |
html()
Get the combined inner HTML of all matched elements. |
|
Elements |
html(String html)
Set the inner HTML of each matched element. |
|
int |
indexOf(Object o)
|
|
boolean |
is(String query)
Test if any of the matched elements match the supplied query. |
|
boolean |
isEmpty()
|
|
Iterator<Element> |
iterator()
|
|
Element |
last()
Get the last matched element. |
|
int |
lastIndexOf(Object o)
|
|
ListIterator<Element> |
listIterator()
|
|
ListIterator<Element> |
listIterator(int index)
|
|
Elements |
not(String query)
Remove elements from this list that match the Selector query. |
|
String |
outerHtml()
Get the combined outer HTML of all matched elements. |
|
Elements |
parents()
Get all of the parents and ancestor elements of the matched elements. |
|
Elements |
prepend(String html)
Add the supplied HTML to the start of each matched element's inner HTML. |
|
Elements |
remove()
Remove each matched element from the DOM. |
|
Element |
remove(int index)
|
|
boolean |
remove(Object o)
|
|
boolean |
removeAll(Collection<?> c)
|
|
Elements |
removeAttr(String attributeKey)
Remove an attribute from every matched element. |
|
Elements |
removeClass(String className)
Remove the class name from every matched element's class attribute, if present. |
|
boolean |
retainAll(Collection<?> c)
|
|
Elements |
select(String query)
Find matching elements within this element list. |
|
Element |
set(int index,
Element element)
|
|
int |
size()
|
|
List<Element> |
subList(int fromIndex,
int toIndex)
|
|
Elements |
tagName(String tagName)
Update the tag name of each matched element. |
|
String |
text()
Get the combined text of all the matched elements. |
|
Object[] |
toArray()
|
|
|
toArray(T[] a)
|
|
Elements |
toggleClass(String className)
Toggle the class name on every matched element's class attribute. |
|
String |
toString()
Get the combined outer HTML of all matched elements. |
|
Elements |
traverse(NodeVisitor nodeVisitor)
Perform a depth-first traversal on each of the selected elements. |
|
Elements |
unwrap()
Removes the matched elements from the DOM, and moves their children up into their parents. |
|
String |
val()
Get the form element's value of the first matched element. |
|
Elements |
val(String value)
Set the form element's value in each of the matched elements. |
|
Elements |
wrap(String html)
Wrap the supplied HTML around each matched elements. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Elements()
public Elements(int initialCapacity)
public Elements(Collection<Element> elements)
public Elements(List<Element> elements)
public Elements(Element... elements)
Method Detail |
---|
public Elements clone()
clone
in class Object
public String attr(String attributeKey)
attributeKey
- The attribute key.
hasAttr(String)
public boolean hasAttr(String attributeKey)
attributeKey
- attribute key
public Elements attr(String attributeKey, String attributeValue)
attributeKey
- attribute keyattributeValue
- attribute value
public Elements removeAttr(String attributeKey)
attributeKey
- The attribute to remove.
public Elements addClass(String className)
class
attribute.
className
- class name to add
public Elements removeClass(String className)
class
attribute, if present.
className
- class name to remove
public Elements toggleClass(String className)
class
attribute.
className
- class name to add if missing, or remove if present, from every element.
public boolean hasClass(String className)
class
attribute.
className
- class name to check for
public String val()
Element.val()
public Elements val(String value)
value
- The value to set into each matched element
public String text()
Note that it is possible to get repeats if the matched elements contain both parent elements and their own children, as the Element.text() method returns the combined text of a parent and all its children.
Element.text()
public boolean hasText()
public String html()
text()
,
outerHtml()
public String outerHtml()
text()
,
html()
public String toString()
outerHtml()
.
toString
in class Object
text()
,
html()
public Elements tagName(String tagName)
<i>
to a <em>
, do
doc.select("i").tagName("em");
tagName
- the new tag name
Element.tagName(String)
public Elements html(String html)
html
- HTML to parse and set into each matched element.
Element.html(String)
public Elements prepend(String html)
html
- HTML to add inside each element, before the existing HTML
Element.prepend(String)
public Elements append(String html)
html
- HTML to add inside each element, after the existing HTML
Element.append(String)
public Elements before(String html)
html
- HTML to insert before each element
Element.before(String)
public Elements after(String html)
html
- HTML to insert after each element
Element.after(String)
public Elements wrap(String html)
<p><b>This</b> is <b>Jsoup</b></p>
,
doc.select("b").wrap("<i></i>");
becomes <p><i><b>This</b></i> is <i><b>jsoup</b></i></p>
html
- HTML to wrap around each element, e.g. <div class="head"></div>
. Can be arbitrarily deep.
Element.wrap(java.lang.String)
public Elements unwrap()
<div><font>One</font> <font><a href="/">Two</a></font></div>
doc.select("font").unwrap();
<div>One <a href="/">Two</a></div>
Node.unwrap()
public Elements empty()
E.g. HTML: <div><p>Hello <b>there</b></p> <p>now</p></div>
doc.select("p").empty();
HTML = <div><p></p> <p></p></div>
Element.empty()
,
remove()
public Elements remove()
E.g. HTML: <div><p>Hello</p> <p>there</p> <img /></div>
doc.select("p").remove();
HTML = <div> <img /></div>
Note that this method should not be used to clean user-submitted HTML; rather, use Cleaner
to clean HTML.
Element.empty()
,
empty()
public Elements select(String query)
query
- A Selector
query
public Elements not(String query)
Selector
query.
E.g. HTML: <div class=logo>One</div> <div>Two</div>
Elements divs = doc.select("div").not("#logo");
Result: divs: [<div>Two</div>]
query
- the selector query whose results should be removed from these elements
public Elements eq(int index)
See also get(int)
to retrieve an Element.
index
- the (zero-based) index of the element in the list to retain
public boolean is(String query)
query
- A selector
public Elements parents()
public Element first()
null
if contents is empty;public Element last()
null
if contents is empty.public Elements traverse(NodeVisitor nodeVisitor)
nodeVisitor
- the visitor callbacks to perform on each node
public int size()
size
in interface Collection<Element>
size
in interface List<Element>
public boolean isEmpty()
isEmpty
in interface Collection<Element>
isEmpty
in interface List<Element>
public boolean contains(Object o)
contains
in interface Collection<Element>
contains
in interface List<Element>
public Iterator<Element> iterator()
iterator
in interface Iterable<Element>
iterator
in interface Collection<Element>
iterator
in interface List<Element>
public Object[] toArray()
toArray
in interface Collection<Element>
toArray
in interface List<Element>
public <T> T[] toArray(T[] a)
toArray
in interface Collection<Element>
toArray
in interface List<Element>
public boolean add(Element element)
add
in interface Collection<Element>
add
in interface List<Element>
public boolean remove(Object o)
remove
in interface Collection<Element>
remove
in interface List<Element>
public boolean containsAll(Collection<?> c)
containsAll
in interface Collection<Element>
containsAll
in interface List<Element>
public boolean addAll(Collection<? extends Element> c)
addAll
in interface Collection<Element>
addAll
in interface List<Element>
public boolean addAll(int index, Collection<? extends Element> c)
addAll
in interface List<Element>
public boolean removeAll(Collection<?> c)
removeAll
in interface Collection<Element>
removeAll
in interface List<Element>
public boolean retainAll(Collection<?> c)
retainAll
in interface Collection<Element>
retainAll
in interface List<Element>
public void clear()
clear
in interface Collection<Element>
clear
in interface List<Element>
public boolean equals(Object o)
equals
in interface Collection<Element>
equals
in interface List<Element>
equals
in class Object
public int hashCode()
hashCode
in interface Collection<Element>
hashCode
in interface List<Element>
hashCode
in class Object
public Element get(int index)
get
in interface List<Element>
public Element set(int index, Element element)
set
in interface List<Element>
public void add(int index, Element element)
add
in interface List<Element>
public Element remove(int index)
remove
in interface List<Element>
public int indexOf(Object o)
indexOf
in interface List<Element>
public int lastIndexOf(Object o)
lastIndexOf
in interface List<Element>
public ListIterator<Element> listIterator()
listIterator
in interface List<Element>
public ListIterator<Element> listIterator(int index)
listIterator
in interface List<Element>
public List<Element> subList(int fromIndex, int toIndex)
subList
in interface List<Element>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |