Package org.jsoup.nodes
Class LeafNode
- java.lang.Object
-
- org.jsoup.nodes.Node
-
- org.jsoup.nodes.LeafNode
-
- All Implemented Interfaces:
java.lang.Cloneable
- Direct Known Subclasses:
Comment,DataNode,DocumentType,TextNode,XmlDeclaration
abstract class LeafNode extends Node
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.List<Node>EmptyNodes(package private) java.lang.Objectvalue-
Fields inherited from class org.jsoup.nodes.Node
EmptyString, parentNode, siblingIndex
-
-
Constructor Summary
Constructors Constructor Description LeafNode()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringabsUrl(java.lang.String key)Get an absolute URL from a URL attribute that may be relative (i.e.java.lang.Stringattr(java.lang.String key)Get an attribute's value by its key.Nodeattr(java.lang.String key, java.lang.String value)Set an attribute (key=value).Attributesattributes()Get all of the element's attributes.java.lang.StringbaseUri()Get the base URI of this node.intchildNodeSize()Get the number of child nodes that this node holds.(package private) java.lang.StringcoreValue()(package private) voidcoreValue(java.lang.String value)protected voiddoSetBaseUri(java.lang.String baseUri)Set the baseUri for just this node (not its descendants), if this Node tracks base URIs.private voidensureAttributes()protected java.util.List<Node>ensureChildNodes()booleanhasAttr(java.lang.String key)Test if this element has an attribute.protected booleanhasAttributes()Check if this Node has an actual Attributes object.NoderemoveAttr(java.lang.String key)Remove an attribute from this element.-
Methods inherited from class org.jsoup.nodes.Node
addChildren, addChildren, after, after, before, before, childNode, childNodes, childNodesAsArray, childNodesCopy, clearAttributes, clone, doClone, equals, filter, hasParent, hasSameValue, html, indent, nextSibling, nodelistChanged, nodeName, outerHtml, outerHtml, outerHtmlHead, outerHtmlTail, ownerDocument, parent, parentNode, previousSibling, remove, removeChild, reparentChild, replaceChild, replaceWith, root, setBaseUri, setParentNode, setSiblingIndex, shallowClone, siblingIndex, siblingNodes, toString, traverse, unwrap, wrap
-
-
-
-
Field Detail
-
EmptyNodes
private static final java.util.List<Node> EmptyNodes
-
value
java.lang.Object value
-
-
Method Detail
-
hasAttributes
protected final boolean hasAttributes()
Description copied from class:NodeCheck if this Node has an actual Attributes object.- Specified by:
hasAttributesin classNode
-
attributes
public final Attributes 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).
-
ensureAttributes
private void ensureAttributes()
-
coreValue
java.lang.String coreValue()
-
coreValue
void coreValue(java.lang.String value)
-
attr
public java.lang.String attr(java.lang.String key)
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");- Overrides:
attrin 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(java.lang.String key, java.lang.String value)
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
public boolean hasAttr(java.lang.String key)
Description copied from class:NodeTest if this element has an attribute. Case insensitive
-
removeAttr
public Node removeAttr(java.lang.String key)
Description copied from class:NodeRemove an attribute from this element.- Overrides:
removeAttrin classNode- Parameters:
key- The attribute to remove.- Returns:
- this (for chaining)
-
absUrl
public java.lang.String absUrl(java.lang.String key)
Description copied from class:NodeGet 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:
absUrlin 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 java.lang.String baseUri()
Description copied from class:NodeGet the base URI of this node.
-
doSetBaseUri
protected void doSetBaseUri(java.lang.String baseUri)
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.
-
ensureChildNodes
protected java.util.List<Node> ensureChildNodes()
- Specified by:
ensureChildNodesin classNode
-
-