Package org.jsoup.nodes
Class TextNode
java.lang.Object
org.jsoup.nodes.Node
org.jsoup.nodes.TextNode
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
CDataNode
A text node.
- Author:
- Jonathan Hedley, jonathan@hedley.net
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGet an absolute URL from a URL attribute that may be relative (such as an<a href>or<img src>).Get an attribute's value by its key.Set an attribute (key=value).final AttributesGet all of the element's attributes.baseUri()Get the base URI that applies to this node.intGet the number of child nodes that this node holds.clone()Create a stand-alone, deep copy of this node, and all of its children.static TextNodecreateFromEncoded(String encodedText) Create a new TextNode from HTML encoded (aka escaped) data.protected org.jsoup.nodes.LeafNodeprotected voiddoSetBaseUri(String baseUri) Set the baseUri for just this node (not its descendants), if this Node tracks base URIs.empty()Delete all this node's children.Get the (unencoded) text of this text node, including any newlines and spaces present in the original.booleanTest if this Node has an attribute.protected final booleanCheck if this Node has an actual Attributes object.booleanisBlank()Test if this text node is blank -- that is, empty or only whitespace (including newlines).nodeName()Get the node name of this node.removeAttr(String key) Remove an attribute from this node.splitText(int offset) Split this text node into two nodes at the specified string offset.text()Get the text content of this text node.Set the text content of this text node.toString()Gets this node's outer HTML.Methods inherited from class org.jsoup.nodes.Node
addChildren, addChildren, after, after, attributesSize, before, before, childNode, childNodes, childNodesAsArray, childNodesCopy, clearAttributes, equals, filter, forEachNode, hashCode, 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, wrap
-
Constructor Details
-
TextNode
Create a new TextNode representing the supplied (unencoded) text).- Parameters:
text- raw text- See Also:
-
-
Method Details
-
nodeName
Description copied from class:NodeGet the node name of this node. Use for debugging purposes and not logic switching (for that, use instanceof). -
text
Get the text content of this text node.- Returns:
- Unencoded, normalised text.
- See Also:
-
text
Set the text content of this text node.- Parameters:
text- unencoded text- Returns:
- this, for chaining
-
getWholeText
Get the (unencoded) text of this text node, including any newlines and spaces present in the original.- Returns:
- text
-
isBlank
public boolean isBlank()Test if this text node is blank -- that is, empty or only whitespace (including newlines).- Returns:
- true if this document is empty or only whitespace, false if it contains any text content.
-
splitText
Split this text node into two nodes at the specified string offset. After splitting, this node will contain the original text up to the offset, and will have a new text node sibling containing the text after the offset.- Parameters:
offset- string offset point to split node at.- Returns:
- the newly created text node containing the text after the offset.
-
toString
Description copied from class:NodeGets this node's outer HTML. -
clone
Description copied from class:NodeCreate a stand-alone, deep copy of this node, and all of its children. The cloned node will have no siblings or parent node. As a stand-alone object, any changes made to the clone or any of its children will not impact the original node.The cloned node may be adopted into another Document or node structure using
Element.appendChild(Node). -
createFromEncoded
Create a new TextNode from HTML encoded (aka escaped) data.- Parameters:
encodedText- Text containing encoded HTML (e.g. <)- Returns:
- TextNode containing unencoded data (e.g. <)
-
hasAttributes
protected final boolean hasAttributes()Description copied from class:NodeCheck if this Node has an actual Attributes object.- Specified by:
hasAttributesin classNode
-
attributes
Description copied from class:NodeGet all of the element's attributes.- Specified by:
attributesin classNode- Returns:
- attributes (which implements iterable, in same order as presented in original HTML).
-
attr
Description copied from class:NodeGet an attribute's value by its key. Case insensitiveTo get an absolute URL from an attribute that may be a relative URL, prefix the key with
E.g.:abs, which is a shortcut to theNode.absUrl(java.lang.String)method.String url = a.attr("abs:href"); -
attr
Description copied from class:NodeSet an attribute (key=value). If the attribute already exists, it is replaced. The attribute key comparison is case insensitive. The key will be set with case sensitivity as set in the parser settings. -
hasAttr
Description copied from class:NodeTest if this Node has an attribute. Case insensitive. -
removeAttr
Description copied from class:NodeRemove an attribute from this node.- Overrides:
removeAttrin classNode- Parameters:
key- The attribute to remove.- Returns:
- this (for chaining)
-
absUrl
Description copied from class:NodeGet an absolute URL from a URL attribute that may be relative (such as an<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://orhttps://etc), and it successfully parses as a URL, the attribute is returned directly. Otherwise, it is treated as a URL relative to the element'sNode.baseUri(), and made absolute using that.As an alternate, you can use the
Node.attr(java.lang.String)method with theabs:prefix, e.g.:String absUrl = linkEl.attr("abs:href"); -
baseUri
Description copied from class:NodeGet the base URI that applies to this node. Will return an empty string if not defined. Used to make relative links absolute. -
doSetBaseUri
Description copied from class:NodeSet the baseUri for just this node (not its descendants), if this Node tracks base URIs.- Specified by:
doSetBaseUriin classNode- Parameters:
baseUri- new URI
-
childNodeSize
public int childNodeSize()Description copied from class:NodeGet the number of child nodes that this node holds.- Specified by:
childNodeSizein classNode- Returns:
- the number of child nodes that this node holds.
-
empty
Description copied from class:NodeDelete all this node's children. -
ensureChildNodes
- Specified by:
ensureChildNodesin classNode
-
doClone
-