public abstract class Node
extends java.lang.Object
implements java.lang.Cloneable
Modifier | Constructor and Description |
---|---|
protected |
Node()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
absUrl(java.lang.String attributeKey)
Get an absolute URL from a URL attribute that may be relative (i.e.
|
protected void |
addChildren(int index,
Node... children) |
protected void |
addChildren(Node... children) |
Node |
after(Node node)
Insert the specified node into the DOM after this node (i.e.
|
Node |
after(java.lang.String html)
Insert the specified HTML into the DOM after this node (i.e.
|
java.lang.String |
attr(java.lang.String attributeKey)
Get an attribute's value by its key.
|
Node |
attr(java.lang.String attributeKey,
java.lang.String attributeValue)
Set an attribute (key=value).
|
abstract Attributes |
attributes()
Get all of the element's attributes.
|
abstract java.lang.String |
baseUri()
Get the base URI of this node.
|
Node |
before(Node node)
Insert the specified node into the DOM before this node (i.e.
|
Node |
before(java.lang.String html)
Insert the specified HTML into the DOM before this node (i.e.
|
Node |
childNode(int index)
Get a child node by its 0-based index.
|
java.util.List<Node> |
childNodes()
Get this node's children.
|
protected Node[] |
childNodesAsArray() |
java.util.List<Node> |
childNodesCopy()
Returns a deep copy of this node's children.
|
abstract int |
childNodeSize()
Get the number of child nodes that this node holds.
|
Node |
clearAttributes()
Clear (remove) all of the attributes in this node.
|
Node |
clone()
Create a stand-alone, deep copy of this node, and all of its children.
|
protected Node |
doClone(Node parent) |
protected abstract void |
doSetBaseUri(java.lang.String baseUri)
Set the baseUri for just this node (not its descendants), if this Node tracks base URIs.
|
protected abstract java.util.List<Node> |
ensureChildNodes() |
boolean |
equals(java.lang.Object o)
Check if this node is the same instance of another (object identity test).
|
Node |
filter(NodeFilter nodeFilter)
Perform a depth-first filtering through this node and its descendants.
|
boolean |
hasAttr(java.lang.String attributeKey)
Test if this element has an attribute.
|
protected abstract boolean |
hasAttributes()
Check if this Node has an actual Attributes object.
|
boolean |
hasParent() |
boolean |
hasSameValue(java.lang.Object o)
Check if this node is has the same content as another node.
|
<T extends java.lang.Appendable> |
html(T appendable)
Write this node and its children to the given
Appendable . |
protected void |
indent(java.lang.Appendable accum,
int depth,
Document.OutputSettings out) |
Node |
nextSibling()
Get this node's next sibling.
|
abstract java.lang.String |
nodeName()
Get the node name of this node.
|
java.lang.String |
outerHtml()
Get the outer HTML of this node.
|
protected void |
outerHtml(java.lang.Appendable accum) |
Document |
ownerDocument()
Gets the Document associated with this Node.
|
Node |
parent()
Gets this node's parent node.
|
Node |
parentNode()
Gets this node's parent node.
|
Node |
previousSibling()
Get this node's previous sibling.
|
void |
remove()
Remove (delete) this node from the DOM tree.
|
Node |
removeAttr(java.lang.String attributeKey)
Remove an attribute from this element.
|
protected void |
removeChild(Node out) |
protected void |
reparentChild(Node child) |
protected void |
replaceChild(Node out,
Node in) |
void |
replaceWith(Node in)
Replace this node in the DOM with the supplied node.
|
Node |
root()
Get this node's root node; that is, its topmost ancestor.
|
void |
setBaseUri(java.lang.String baseUri)
Update the base URI of this node and all of its descendants.
|
protected void |
setParentNode(Node parentNode) |
protected void |
setSiblingIndex(int siblingIndex) |
Node |
shallowClone()
Create a stand-alone, shallow copy of this node.
|
int |
siblingIndex()
Get the list index of this node in its node sibling list.
|
java.util.List<Node> |
siblingNodes()
Retrieves this node's sibling nodes.
|
java.lang.String |
toString() |
Node |
traverse(NodeVisitor nodeVisitor)
Perform a depth-first traversal through this node and its descendants.
|
Node |
unwrap()
Removes this node from the DOM, and moves its children up into the node's parent.
|
Node |
wrap(java.lang.String html)
Wrap the supplied HTML around this node.
|
protected Node()
public abstract java.lang.String nodeName()
protected abstract boolean hasAttributes()
public boolean hasParent()
public java.lang.String attr(java.lang.String attributeKey)
To get an absolute URL from an attribute that may be a relative URL, prefix the key with abs
,
which is a shortcut to the absUrl(java.lang.String)
method.
String url = a.attr("abs:href");
attributeKey
- The attribute key.attributes()
,
hasAttr(String)
,
absUrl(String)
public abstract Attributes attributes()
public Node attr(java.lang.String attributeKey, java.lang.String attributeValue)
attributeKey
- The attribute key.attributeValue
- The attribute value.public boolean hasAttr(java.lang.String attributeKey)
attributeKey
- The attribute key to check.public Node removeAttr(java.lang.String attributeKey)
attributeKey
- The attribute to remove.public Node clearAttributes()
public abstract java.lang.String baseUri()
protected abstract void doSetBaseUri(java.lang.String baseUri)
baseUri
- new URIpublic void setBaseUri(java.lang.String baseUri)
baseUri
- base URI to setpublic java.lang.String absUrl(java.lang.String attributeKey)
<a href>
or
<img src>
).
E.g.: String absUrl = linkEl.absUrl("href");
If the attribute value is already absolute (i.e. it starts with a protocol, like
http://
or https://
etc), and it successfully parses as a URL, the attribute is
returned directly. Otherwise, it is treated as a URL relative to the element's baseUri()
, and made
absolute using that.
As an alternate, you can use the attr(java.lang.String)
method with the abs:
prefix, e.g.:
String absUrl = linkEl.attr("abs:href");
attributeKey
- The attribute keyattr(java.lang.String)
,
URL.URL(java.net.URL, String)
protected abstract java.util.List<Node> ensureChildNodes()
public Node childNode(int index)
index
- index of child nodeIndexOutOfBoundsException
if the index is out of bounds.public java.util.List<Node> childNodes()
public java.util.List<Node> childNodesCopy()
public abstract int childNodeSize()
protected Node[] childNodesAsArray()
public Node parent()
public final Node parentNode()
public Node root()
this
.public Document ownerDocument()
public void remove()
public Node before(java.lang.String html)
html
- HTML to add before this nodeafter(String)
public Node before(Node node)
node
- to add before this nodeafter(org.jsoup.nodes.Node)
public Node after(java.lang.String html)
html
- HTML to add after this nodebefore(String)
public Node after(Node node)
node
- to add after this nodebefore(org.jsoup.nodes.Node)
public Node wrap(java.lang.String html)
html
- HTML to wrap around this element, e.g. <div class="head"></div>
. Can be arbitrarily deep.public Node unwrap()
For example, with the input html:
<div>One <span>Two <b>Three</b></span></div>
element.unwrap()
on the span
element will result in the html:
<div>One Two <b>Three</b></div>
"Two "
TextNode
being returned.remove()
,
wrap(String)
public void replaceWith(Node in)
in
- the node that will will replace the existing node.protected void setParentNode(Node parentNode)
protected void removeChild(Node out)
protected void addChildren(Node... children)
protected void addChildren(int index, Node... children)
protected void reparentChild(Node child)
public java.util.List<Node> siblingNodes()
node.parent.childNodes()
, but does not
include this node (a node is not a sibling of itself).public Node nextSibling()
public Node previousSibling()
public int siblingIndex()
Element.elementSiblingIndex()
protected void setSiblingIndex(int siblingIndex)
public Node traverse(NodeVisitor nodeVisitor)
nodeVisitor
- the visitor callbacks to perform on each nodepublic Node filter(NodeFilter nodeFilter)
nodeFilter
- the filter callbacks to perform on each nodepublic java.lang.String outerHtml()
protected void outerHtml(java.lang.Appendable accum)
public <T extends java.lang.Appendable> T html(T appendable)
Appendable
.appendable
- the Appendable
to write to.Appendable
, for chaining.public java.lang.String toString()
toString
in class java.lang.Object
protected void indent(java.lang.Appendable accum, int depth, Document.OutputSettings out) throws java.io.IOException
java.io.IOException
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- other object to compare toto compare nodes by their value
public boolean hasSameValue(java.lang.Object o)
o
- other object to compare topublic Node clone()
The cloned node may be adopted into another Document or node structure using Element.appendChild(org.jsoup.nodes.Node)
.
clone
in class java.lang.Object
shallowClone()
public Node shallowClone()
clone()