Package org.jsoup.select
Class Nodes<T extends Node>
java.lang.Object
java.util.AbstractCollection<T>
java.util.AbstractList<T>
java.util.ArrayList<T>
org.jsoup.select.Nodes<T>
- All Implemented Interfaces:
-
Serializable
,Cloneable
,Iterable<T>
,Collection<T>
,List<T>
,RandomAccess
,SequencedCollection<T>
- Direct Known Subclasses:
-
Elements
A list of
Node
objects, with methods that act on every node in the list.
Methods that set
, remove
, or replace
nodes in the list will also act on the underlying DOM
.
If there are other bulk methods (perhaps from Elements) that would be useful here, please provide feedback.
- Since:
- 1.21.1
- See Also:
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionafter
(String html) Insert the supplied HTML after each matched nodes's outer HTML.ArrayList
<T> asList()
Convenience method to get the Nodes as a plain ArrayList.before
(String html) Insert the supplied HTML before each matched node's outer HTML.void
clear()
Removes all the nodes from this list, and each of them from the DOM.clone()
Creates a deep copy of these nodes.deselect
(int index) Remove the node at the specified index in this list, but not from the DOM.boolean
deselect
(Object o) Remove the specified node from this list, but not from the DOM.void
Likeclear(
, removes all the nodes from this list, but not from the DOM.) @Nullable T
first()
Get the first matched element.@Nullable T
last()
Get the last matched element.String
Get the combined outer HTML of all matched nodes.remove()
Remove each matched node from the DOM.remove
(int index) Remove the node at the specified index in this list, and from the DOM.boolean
remove
(Object o) Remove the specified node from this list, and from the DOM.boolean
removeAll
(Collection<?> c) Removes from this list, and from the DOM, each of the nodes that are contained in the specified collection and are in this list.boolean
Remove from the list, and from the DOM, all nodes in this list that mach the given predicate.void
replaceAll
(UnaryOperator<T> operator) Replace each node in this list with the result of the operator, and update the DOM.boolean
retainAll
(Collection<?> toRemove) Retain in this list, and in the DOM, only the nodes that are in the specified collection and are in this list.Replace the node at the specified index in this list, and in the DOM.String
toString()
Get the combined outer HTML of all matched nodes.wrap
(String html) Wrap the supplied HTML around each matched node.Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, addFirst, addLast, contains, ensureCapacity, equals, forEach, get, getFirst, getLast, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, removeFirst, removeLast, removeRange, size, sort, spliterator, subList, toArray, toArray, trimToSize
Methods inherited from class java.util.AbstractCollection
containsAll
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, stream, toArray
Methods inherited from interface java.util.List
containsAll, reversed
-
Constructor Details
-
Method Details
-
clone
Creates a deep copy of these nodes. -
asList
Convenience method to get the Nodes as a plain ArrayList. This allows modification to the list of nodes without modifying the source Document. I.e. whereas callingnodes.remove(
will remove the nodes from both the Nodes and the DOM,0) nodes.asList(
will remove the node from the list only.).remove(0) Each Node is still the same DOM connected Node.
- Returns:
- a new ArrayList containing the nodes in this list
- See Also:
-
remove
Remove each matched node from the DOM.The nodes will still be retained in this list, in case further processing of them is desired.
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.- Returns:
- this, for chaining
- See Also:
-
outerHtml
public String outerHtml()Get the combined outer HTML of all matched nodes.- Returns:
- string of all node's outer HTML.
- See Also:
-
toString
public String toString()Get the combined outer HTML of all matched nodes. Alias ofouterHtml(
.) -
before
Insert the supplied HTML before each matched node's outer HTML.- Parameters:
-
html
- HTML to insert before each node - Returns:
- this, for chaining
- See Also:
-
after
Insert the supplied HTML after each matched nodes's outer HTML.- Parameters:
-
html
- HTML to insert after each node - Returns:
- this, for chaining
- See Also:
-
wrap
Wrap the supplied HTML around each matched node. For example, with HTML<p><b>This</b> is <b>Jsoup</b></p>
,doc.select(
becomes"b").wrap("<i></i>"); <p><i><b>This</b></i> is <i><b>jsoup</b></i></p>
- Parameters:
-
html
- HTML to wrap around each node, e.g.<div class="head"></div>
. Can be arbitrarily deep. - Returns:
- this (for chaining)
- See Also:
-
first
Get the first matched element.- Returns:
-
The first matched element, or
null
if contents is empty.
-
last
Get the last matched element.- Returns:
-
The last matched element, or
null
if contents is empty.
-
set
Replace the node at the specified index in this list, and in the DOM. -
remove
Remove the node at the specified index in this list, and from the DOM. -
remove
public boolean remove(Object o) Remove the specified node from this list, and from the DOM. -
deselect
Remove the node at the specified index in this list, but not from the DOM.- Parameters:
-
index
- the index of the node to be removed - Returns:
- the old node at this index
- See Also:
-
deselect
public boolean deselect(Object o) Remove the specified node from this list, but not from the DOM.- Parameters:
-
o
- node to be removed from this list, if present - Returns:
- if this list contained the Node
- See Also:
-
clear
public void clear()Removes all the nodes from this list, and each of them from the DOM. -
deselectAll
public void deselectAll()Likeclear(
, removes all the nodes from this list, but not from the DOM.) - See Also:
-
removeAll
public boolean removeAll(Collection<?> c) Removes from this list, and from the DOM, each of the nodes that are contained in the specified collection and are in this list.- Specified by:
-
removeAll
in interfaceCollection<T extends Node>
- Specified by:
-
removeAll
in interfaceList<T extends Node>
- Overrides:
-
removeAll
in classArrayList<T extends Node>
- Parameters:
-
c
- collection containing nodes to be removed from this list - Returns:
-
true
if nodes were removed from this list
-
retainAll
public boolean retainAll(Collection<?> toRemove) Retain in this list, and in the DOM, only the nodes that are in the specified collection and are in this list. In other words, remove nodes from this list and the DOM any item that is in this list but not in the specified collection.- Specified by:
-
retainAll
in interfaceCollection<T extends Node>
- Specified by:
-
retainAll
in interfaceList<T extends Node>
- Overrides:
-
retainAll
in classArrayList<T extends Node>
- Parameters:
-
toRemove
- collection containing nodes to be retained in this list - Returns:
-
true
if nodes were removed from this list - Since:
- 1.17.1
-
removeIf
Remove from the list, and from the DOM, all nodes in this list that mach the given predicate. -
replaceAll
Replace each node in this list with the result of the operator, and update the DOM.
-