Package org.jsoup.nodes
Class LeafNode
java.lang.Object
org.jsoup.nodes.Node
org.jsoup.nodes.LeafNode
- All Implemented Interfaces:
-
Cloneable
- Direct Known Subclasses:
-
Comment,DataNode,DocumentType,TextNode,XmlDeclaration
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionStringabsUrl(String key) Get an absolute URL from a URL attribute that may be relative (such as an<a href>or<img src>).Stringattr(String key) Get an attribute's value by its key.attr(String key, String value) Set an attribute (key=value).final AttributesGet each of the Element's attributes.StringbaseUri()Get the base URI that applies to this node.intGet the number of child nodes that this node holds.protected 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.protected List<Node> booleanhasAttr(String key) Test if this Node has an attribute.protected final booleanCheck if this Node has an actual Attributes object.StringGet the node's value.@Nullable Elementparent()Gets this node's parent node.removeAttr(String key) Remove an attribute from this node.Methods inherited from class org.jsoup.nodes.Node
addChildren, addChildren, after, after, attributesSize, before, before, childNode, childNodes, childNodesAsArray, childNodesCopy, clearAttributes, clone, equals, filter, firstChild, firstSibling, forEachNode, hashCode, hasParent, hasSameValue, html, indent, lastChild, lastSibling, nameIs, nextElementSibling, nextSibling, nodeName, nodeStream, nodeStream, normalName, outerHtml, outerHtml, outerHtml, ownerDocument, parentElement, parentElementIs, parentNameIs, parentNode, previousElementSibling, previousSibling, remove, removeChild, reparentChild, replaceChild, replaceWith, root, setBaseUri, setParentNode, setSiblingIndex, shallowClone, siblingIndex, siblingNodes, sourceRange, toString, traverse, unwrap, wrapMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Constructor Details
-
Method Details
-
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 each of the Element's attributes.- Specified by:
-
attributesin classNode - Returns:
- attributes (which implements Iterable, with the same order as presented in the original HTML).
-
parent
Description copied from class:NodeGets this node's parent node. This is always an Element. -
nodeValue
public String nodeValue()Description copied from class:NodeGet the node's value. For a TextNode, the whole text; for a Comment, the comment data; for an Element, wholeOwnText. Returns "" if there is no value. -
attr
public String attr(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(method.java.lang.String) 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
public boolean hasAttr(String key) 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
public String absUrl(String key) 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(method with thejava.lang.String) abs:prefix, e.g.:String absUrl = linkEl.attr("abs:href"); -
baseUri
public String 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
protected void doSetBaseUri(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.
-
empty
Description copied from class:NodeDelete all this node's children. -
ensureChildNodes
- Specified by:
-
ensureChildNodesin classNode
-
doClone
-