| Constructor and Description |
|---|
TextNode(String text)
Create a new TextNode representing the supplied (unencoded) text).
|
| Modifier and Type | Method and Description |
|---|---|
String |
absUrl(String key)
Get an absolute URL from a URL attribute that may be relative (such as an
<a href> or
<img src>). |
String |
attr(String key)
Get an attribute's value by its key.
|
Node |
attr(String key,
String value)
Set an attribute (key=value).
|
Attributes |
attributes()
Get all of the element's attributes.
|
String |
baseUri()
Get the base URI that applies to this node.
|
int |
childNodeSize()
Get the number of child nodes that this node holds.
|
TextNode |
clone()
Create a stand-alone, deep copy of this node, and all of its children.
|
static TextNode |
createFromEncoded(String encodedText)
Create a new TextNode from HTML encoded (aka escaped) data.
|
protected org.jsoup.nodes.LeafNode |
doClone(Node parent) |
protected void |
doSetBaseUri(String baseUri)
Set the baseUri for just this node (not its descendants), if this Node tracks base URIs.
|
Node |
empty()
Delete all this node's children.
|
protected List<Node> |
ensureChildNodes() |
String |
getWholeText()
Get the (unencoded) text of this text node, including any newlines and spaces present in the original.
|
boolean |
hasAttr(String key)
Test if this Node has an attribute.
|
protected boolean |
hasAttributes()
Check if this Node has an actual Attributes object.
|
boolean |
isBlank()
Test if this text node is blank -- that is, empty or only whitespace (including newlines).
|
String |
nodeName()
Get the node name of this node.
|
Node |
removeAttr(String key)
Remove an attribute from this node.
|
TextNode |
splitText(int offset)
Split this text node into two nodes at the specified string offset.
|
String |
text()
Get the text content of this text node.
|
TextNode |
text(String text)
Set the text content of this text node.
|
String |
toString()
Gets this node's outer HTML.
|
addChildren, addChildren, after, after, attributesSize, before, before, childNode, childNodes, childNodesAsArray, childNodesCopy, clearAttributes, equals, filter, hasParent, hasSameValue, html, indent, nextSibling, outerHtml, outerHtml, ownerDocument, parent, parentNode, previousSibling, remove, removeChild, reparentChild, replaceChild, replaceWith, root, setBaseUri, setParentNode, setSiblingIndex, shallowClone, siblingIndex, siblingNodes, traverse, unwrap, wrappublic TextNode(String text)
text - raw textcreateFromEncoded(String)public String nodeName()
Nodepublic String text()
getWholeText()public TextNode text(String text)
text - unencoded textpublic String getWholeText()
public boolean isBlank()
public TextNode splitText(int offset)
offset - string offset point to split node at.public String toString()
NodetoString in class NodeNode.outerHtml()public TextNode clone()
Node
The cloned node may be adopted into another Document or node structure using Element.appendChild(Node).
clone in class NodeNode.shallowClone()public static TextNode createFromEncoded(String encodedText)
encodedText - Text containing encoded HTML (e.g. <)protected final boolean hasAttributes()
NodehasAttributes in class Nodepublic final Attributes attributes()
Nodeattributes in class Nodepublic String attr(String key)
Node
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 Node.absUrl(java.lang.String) method.
String url = a.attr("abs:href");attr in class Nodekey - The attribute key.Node.attributes(),
Node.hasAttr(String),
Node.absUrl(String)public Node attr(String key, String value)
Nodepublic boolean hasAttr(String key)
Nodepublic Node removeAttr(String key)
NoderemoveAttr in class Nodekey - The attribute to remove.public String absUrl(String key)
Node<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 Node.baseUri(), and made
absolute using that.
As an alternate, you can use the Node.attr(java.lang.String) method with the abs: prefix, e.g.:
String absUrl = linkEl.attr("abs:href");
absUrl in class Nodekey - The attribute keyNode.attr(java.lang.String),
URL(java.net.URL, String)public String baseUri()
NodebaseUri in class NodeNode.absUrl(java.lang.String)protected void doSetBaseUri(String baseUri)
NodedoSetBaseUri in class NodebaseUri - new URIpublic int childNodeSize()
NodechildNodeSize in class Nodeprotected List<Node> ensureChildNodes()
ensureChildNodes in class NodeCopyright © 2009–2025 Jonathan Hedley. All rights reserved.