Package org.jsoup.nodes
Class DataNode
- java.lang.Object
-
- org.jsoup.nodes.Node
-
- org.jsoup.nodes.DataNode
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
absUrl(String key)
Get an absolute URL from a URL attribute that may be relative (i.e.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.DataNode
clone()
Create a stand-alone, deep copy of this node, and all of its children.static DataNode
createFromEncoded(String encodedData, String baseUri)
Create a new DataNode from HTML encoded 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
getWholeData()
Get the data contents of this node.boolean
hasAttr(String key)
Test if this element has an attribute.protected boolean
hasAttributes()
Check if this Node has an actual Attributes object.String
nodeName()
Get the node name of this node.Node
removeAttr(String key)
Remove an attribute from this node.DataNode
setWholeData(String data)
Set the data contents of this node.String
toString()
Gets this node's outer HTML.-
Methods inherited from class org.jsoup.nodes.Node
addChildren, addChildren, after, after, 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, wrap
-
-
-
-
Constructor Detail
-
DataNode
public DataNode(String data)
Create a new DataNode.- Parameters:
data
- data contents
-
-
Method Detail
-
nodeName
public String nodeName()
Description copied from class:Node
Get the node name of this node. Use for debugging purposes and not logic switching (for that, use instanceof).
-
getWholeData
public String getWholeData()
Get the data contents of this node. Will be unescaped and with original new lines, space etc.- Returns:
- data
-
setWholeData
public DataNode setWholeData(String data)
Set the data contents of this node.- Parameters:
data
- unencoded data- Returns:
- this node, for chaining
-
toString
public String toString()
Description copied from class:Node
Gets this node's outer HTML.- Overrides:
toString
in classNode
- Returns:
- outer HTML.
- See Also:
Node.outerHtml()
-
clone
public DataNode clone()
Description copied from class:Node
Create 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)
.- Overrides:
clone
in classNode
- Returns:
- a stand-alone cloned node, including clones of any children
- See Also:
Node.shallowClone()
-
createFromEncoded
public static DataNode createFromEncoded(String encodedData, String baseUri)
Create a new DataNode from HTML encoded data.- Parameters:
encodedData
- encoded databaseUri
- bass URI- Returns:
- new DataNode
-
hasAttributes
protected final boolean hasAttributes()
Description copied from class:Node
Check if this Node has an actual Attributes object.- Specified by:
hasAttributes
in classNode
-
attributes
public final Attributes attributes()
Description copied from class:Node
Get all of the element's attributes.- Specified by:
attributes
in classNode
- Returns:
- attributes (which implements iterable, in same order as presented in original HTML).
-
attr
public String attr(String key)
Description copied from class:Node
Get 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");
- Overrides:
attr
in classNode
- Parameters:
key
- The attribute key.- Returns:
- The attribute, or empty string if not present (to avoid nulls).
- See Also:
Node.attributes()
,Node.hasAttr(String)
,Node.absUrl(String)
-
attr
public Node attr(String key, String value)
Description copied from class:Node
Set 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
public boolean hasAttr(String key)
Description copied from class:Node
Test if this element has an attribute. Case insensitive
-
removeAttr
public Node removeAttr(String key)
Description copied from class:Node
Remove an attribute from this node.- Overrides:
removeAttr
in classNode
- Parameters:
key
- The attribute to remove.- Returns:
- this (for chaining)
-
absUrl
public String absUrl(String key)
Description copied from class:Node
Get an absolute URL from a URL attribute that may be relative (i.e. 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");
- Overrides:
absUrl
in classNode
- Parameters:
key
- The attribute key- Returns:
- An absolute URL if one could be made, or an empty string (not null) if the attribute was missing or could not be made successfully into a URL.
- See Also:
Node.attr(java.lang.String)
,URL(java.net.URL, String)
-
baseUri
public String baseUri()
Description copied from class:Node
Get the base URI that applies to this node. Empty string if not defined. Used to make relative links absolute to.
-
doSetBaseUri
protected void doSetBaseUri(String baseUri)
Description copied from class:Node
Set the baseUri for just this node (not its descendants), if this Node tracks base URIs.- Specified by:
doSetBaseUri
in classNode
- Parameters:
baseUri
- new URI
-
childNodeSize
public int childNodeSize()
Description copied from class:Node
Get the number of child nodes that this node holds.- Specified by:
childNodeSize
in classNode
- Returns:
- the number of child nodes that this node holds.
-
ensureChildNodes
protected List<Node> ensureChildNodes()
- Specified by:
ensureChildNodes
in classNode
-
-