Class Node
The base, abstract Node model.
Namespace: Supremes.Nodes
Assembly: Supremes.dll
Syntax
public abstract class Node : object
Remarks
Elements, Documents, Comments etc are all Node instances.
Properties
Attributes
Get all of the element's attributes.
Declaration
public virtual Attributes Attributes { get; }
Property Value
Type | Description |
---|---|
Attributes | attributes (which implements iterable, in same order as presented in original HTML). |
BaseUri
Get or Set the base URI of this node. When set, it updates the base URI of this node and all of its descendants.
Declaration
public string BaseUri { get; set; }
Property Value
Type | Description |
---|---|
System.String | base URI to set |
ChildNodes
Get this node's children.
Declaration
public IReadOnlyList<Node> ChildNodes { get; }
Property Value
Type | Description |
---|---|
IReadOnlyList<Node> | list of children. If no children, returns an empty list. |
Remarks
Presented as an unmodifiable list: new children can not be added, but the child nodes themselves can be manipulated.
ChildNodeSize
Get the number of child nodes that this node holds.
Declaration
public int ChildNodeSize { get; }
Property Value
Type | Description |
---|---|
System.Int32 | the number of child nodes that this node holds. |
NextSibling
Get this node's next sibling.
Declaration
public Node NextSibling { get; }
Property Value
Type | Description |
---|---|
Node | next sibling, or null if this is the last sibling |
OuterHtml
Get the outer HTML of this node.
Declaration
public virtual string OuterHtml { get; }
Property Value
Type | Description |
---|---|
System.String | HTML |
OwnerDocument
Gets the Document associated with this Node.
Declaration
public Document OwnerDocument { get; }
Property Value
Type | Description |
---|---|
Document | the Document associated with this Node, or null if there is no such Document. |
Parent
Gets this node's parent node.
Declaration
public Node Parent { get; }
Property Value
Type | Description |
---|---|
Node | parent node; or null if no parent. |
PreviousSibling
Get this node's previous sibling.
Declaration
public Node PreviousSibling { get; }
Property Value
Type | Description |
---|---|
Node | the previous sibling, or null if this is the first sibling |
SiblingIndex
Get the list index of this node in its node sibling list.
Declaration
public int SiblingIndex { get; }
Property Value
Type | Description |
---|---|
System.Int32 | position in node sibling list |
Remarks
I.e. if this is the first node sibling, returns 0.
See Also
SiblingNodes
Retrieves this node's sibling nodes.
Declaration
public IReadOnlyList<Node> SiblingNodes { get; }
Property Value
Type | Description |
---|---|
IReadOnlyList<Node> | node siblings. If the node has no parent, returns an empty list. |
Remarks
Similar to ChildNodes , but does not include this node (a node is not a sibling of itself).
Methods
AbsUrl(String)
Get an absolute URL from a URL attribute that may be relative
(i.e. an <a href>
or <img src>
).
Declaration
public virtual string AbsUrl(string attributeKey)
Parameters
Type | Name | Description |
---|---|---|
System.String | attributeKey | The attribute key |
Returns
Type | Description |
---|---|
System.String | 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. |
Remarks
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
BaseUri
, and made
absolute using that.
As an alternate, you can use the
Attr(String)
method with the abs:
prefix, e.g.:
string absUrl = linkEl.Attr("abs:href");
This method add trailing slash to domain name: i.e.
from <a id=2 href='http://jsoup.org'>
to "http://jsoup.org/"
See Also
After(Node)
Insert the specified node into the DOM after this node (i.e. as a following sibling).
Declaration
public virtual Node After(Node node)
Parameters
Type | Name | Description |
---|---|---|
Node | node | to add after this node |
Returns
Type | Description |
---|---|
Node | this node, for chaining |
See Also
After(String)
Insert the specified HTML into the DOM after this node (i.e. as a following sibling).
Declaration
public virtual Node After(string html)
Parameters
Type | Name | Description |
---|---|---|
System.String | html | HTML to add after this node |
Returns
Type | Description |
---|---|
Node | this node, for chaining |
See Also
Attr(String)
Get an attribute's value by its key.
Declaration
public virtual string Attr(string attributeKey)
Parameters
Type | Name | Description |
---|---|---|
System.String | attributeKey | The attribute key. |
Returns
Type | Description |
---|---|
System.String | The attribute, or empty string if not present (to avoid nulls). |
Remarks
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
AbsUrl(String)
method.
E.g.:
String url = a.attr("abs:href");
See Also
Attr(String, String)
Set an attribute (key=value).
Declaration
public virtual Node Attr(string attributeKey, string attributeValue)
Parameters
Type | Name | Description |
---|---|---|
System.String | attributeKey | The attribute key. |
System.String | attributeValue | The attribute value. |
Returns
Type | Description |
---|---|
Node | this (for chaining) |
Remarks
If the attribute already exists, it is replaced.
Before(Node)
Insert the specified node into the DOM before this node (i.e. as a preceding sibling).
Declaration
public virtual Node Before(Node node)
Parameters
Type | Name | Description |
---|---|---|
Node | node | to add before this node |
Returns
Type | Description |
---|---|
Node | this node, for chaining |
See Also
Before(String)
Insert the specified HTML into the DOM before this node (i.e. as a preceding sibling).
Declaration
public virtual Node Before(string html)
Parameters
Type | Name | Description |
---|---|---|
System.String | html | HTML to add before this node |
Returns
Type | Description |
---|---|
Node | this node, for chaining |
See Also
ChildNode(Int32)
Get a child node by its 0-based index.
Declaration
public Node ChildNode(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | index of child node |
Returns
Type | Description |
---|---|
Node | the child node at this index. Throws a
|
ChildNodesCopy()
Returns a deep copy of this node's children.
Declaration
public IList<Node> ChildNodesCopy()
Returns
Type | Description |
---|---|
IList<Node> | a deep copy of this node's children |
Remarks
Changes made to these nodes will not be reflected in the original nodes
Equals(Object)
Compares two Node instances for equality.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj |
Returns
Type | Description |
---|---|
System.Boolean |
GetHashCode()
Returns the hash code for this instance.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 |
HasAttr(String)
Test if this element has an attribute.
Declaration
public virtual bool HasAttr(string attributeKey)
Parameters
Type | Name | Description |
---|---|---|
System.String | attributeKey | The attribute key to check. |
Returns
Type | Description |
---|---|
System.Boolean | true if the attribute exists, false if not. |
Remove()
Remove (delete) this node from the DOM tree.
Declaration
public void Remove()
Remarks
If this node has children, they are also removed.
RemoveAttr(String)
Remove an attribute from this element.
Declaration
public virtual Node RemoveAttr(string attributeKey)
Parameters
Type | Name | Description |
---|---|---|
System.String | attributeKey | The attribute to remove. |
Returns
Type | Description |
---|---|
Node | this (for chaining) |
ReplaceWith(Node)
Replace this node in the DOM with the supplied node.
Declaration
public void ReplaceWith(Node in)
Parameters
Type | Name | Description |
---|---|---|
Node | in | the node that will will replace the existing node. |
ToString()
Converts the value of this instance to a string.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String |
Unwrap()
Removes this node from the DOM, and moves its children up into the node's parent.
Declaration
public Node Unwrap()
Returns
Type | Description |
---|---|
Node | the first child of this node, after the node has been unwrapped. Null if the node had no children. |
Remarks
This has the effect of dropping the node but keeping its children.
For example, with the input html:
<div>One <span>Two <b>Three</b></span></div>
Calling
element.Unwrap()
on the
span
element will result in the html:
<div>One Two <b>Three</b></div>
and the
"Two "
TextNode
being returned.
See Also
Wrap(String)
Wrap the supplied HTML around this node.
Declaration
public Node Wrap(string html)
Parameters
Type | Name | Description |
---|---|---|
System.String | html | HTML to wrap around this element, e.g.
|
Returns
Type | Description |
---|---|
Node | this node, for chaining. |