|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jsoup.nodes.Node
public abstract class Node
The base, abstract Node model. Elements, Documents, Comments etc are all Node instances.
Constructor Summary | |
---|---|
protected |
Node()
Default constructor. |
protected |
Node(String baseUri)
|
protected |
Node(String baseUri,
Attributes attributes)
Create a new Node. |
Method Summary | |
---|---|
String |
absUrl(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(String html)
Insert the specified HTML into the DOM after this node (i.e. |
String |
attr(String attributeKey)
Get an attribute's value by its key. |
Node |
attr(String attributeKey,
String attributeValue)
Set an attribute (key=value). |
Attributes |
attributes()
Get all of the element's attributes. |
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(String html)
Insert the specified HTML into the DOM before this node (i.e. |
Node |
childNode(int index)
Get a child node by index |
List<Node> |
childNodes()
Get this node's children. |
protected Node[] |
childNodesAsArray()
|
Node |
clone()
Create a stand-alone, deep copy of this node, and all of its children. |
protected Node |
doClone(Node parent)
|
boolean |
equals(Object o)
|
boolean |
hasAttr(String attributeKey)
Test if this element has an attribute. |
int |
hashCode()
|
protected void |
indent(StringBuilder accum,
int depth,
Document.OutputSettings out)
|
Node |
nextSibling()
Get this node's next sibling. |
abstract String |
nodeName()
Get the node name of this node. |
String |
outerHtml()
Get the outer HTML of this node. |
protected void |
outerHtml(StringBuilder accum)
|
Document |
ownerDocument()
Gets the Document associated with this Node. |
Node |
parent()
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(String attributeKey)
Remove an attribute from this element. |
protected void |
removeChild(Node out)
|
protected void |
replaceChild(Node out,
Node in)
|
void |
replaceWith(Node in)
Replace this node in the DOM with the supplied node. |
void |
setBaseUri(String baseUri)
Update the base URI of this node. |
protected void |
setParentNode(Node parentNode)
|
protected void |
setSiblingIndex(int siblingIndex)
|
int |
siblingIndex()
Get the list index of this node in its node sibling list. |
List<Node> |
siblingNodes()
Retrieves this node's sibling nodes. |
String |
toString()
|
Node |
unwrap()
Removes this node from the DOM, and moves its children up into the node's parent. |
Node |
wrap(String html)
Wrap the supplied HTML around this node. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
protected Node(String baseUri, Attributes attributes)
baseUri
- base URIattributes
- attributes (not null, but may be empty)protected Node(String baseUri)
protected Node()
Method Detail |
---|
public abstract String nodeName()
public String attr(String attributeKey)
abs
,
which is a shortcut to the absUrl(java.lang.String)
method.
E.g.: String url = a.attr("abs:href");
attributeKey
- The attribute key.
attributes()
,
hasAttr(String)
,
absUrl(String)
public Attributes attributes()
public Node attr(String attributeKey, String attributeValue)
attributeKey
- The attribute key.attributeValue
- The attribute value.
public boolean hasAttr(String attributeKey)
attributeKey
- The attribute key to check.
public Node removeAttr(String attributeKey)
attributeKey
- The attribute to remove.
public String baseUri()
public void setBaseUri(String baseUri)
baseUri
- base URI to setpublic String absUrl(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 key
attr(java.lang.String)
,
URL.URL(java.net.URL, String)
public Node childNode(int index)
index
- index of child node
public List<Node> childNodes()
protected Node[] childNodesAsArray()
public Node parent()
public Document ownerDocument()
public void remove()
public Node before(String html)
html
- HTML to add before this node
after(String)
public Node before(Node node)
node
- to add before this node
after(Node)
public Node after(String html)
html
- HTML to add after this node
before(String)
public Node after(Node node)
node
- to add after this node
before(Node)
public Node wrap(String html)
html
- HTML to wrap around this element, e.g. <div class="head"></div>
. Can be arbitrarily deep.
public Node unwrap()
<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 replaceChild(Node out, Node in)
protected void removeChild(Node out)
protected void addChildren(Node... children)
protected void addChildren(int index, Node... children)
public List<Node> siblingNodes()
node.parent.childNodes()
.
public Node nextSibling()
public Node previousSibling()
public int siblingIndex()
Element.elementSiblingIndex()
protected void setSiblingIndex(int siblingIndex)
public String outerHtml()
protected void outerHtml(StringBuilder accum)
public String toString()
toString
in class Object
protected void indent(StringBuilder accum, int depth, Document.OutputSettings out)
public boolean equals(Object o)
equals
in class Object
public int hashCode()
hashCode
in class Object
public Node clone()
The cloned node may be adopted into another Document or node structure using Element.appendChild(Node)
.
clone
in class Object
protected Node doClone(Node parent)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |