Class NodeExtensions
- Namespace
- AngleSharp.Dom
- Assembly
- AngleSharp.dll
Useful methods for node objects.
public static class NodeExtensions
- Inheritance
-
NodeExtensions
- Inherited Members
Methods
EnsurePreInsertionValidity(INode, INode, INode?)
Ensures the validity for inserting the given node at parent before the provided child. Throws an error is the insertation is invalid.
public static void EnsurePreInsertionValidity(this INode parent, INode node, INode? child)
Parameters
parent
INodeThe origin that will be mutated.
node
INodeThe node to be inserted.
child
INodeThe reference node of the insertation.
FindChild<TNode>(INode)
Tries to find a direct child of a certain type.
public static TNode? FindChild<TNode>(this INode parent) where TNode : class, INode
Parameters
parent
INodeThe parent that contains the elements.
Returns
- TNode
The instance or null.
Type Parameters
TNode
The node type to find.
FindDescendant<TNode>(INode, int)
Tries to find a descendant of a certain type.
public static TNode? FindDescendant<TNode>(this INode parent, int maxDepth = 1024) where TNode : class, INode
Parameters
parent
INodeThe parent that contains the elements.
maxDepth
intThe maximum depth to allow for searching. A value of 0 is equivalent to FindChild.
Returns
- TNode
The instance or null.
Type Parameters
TNode
The node type to find.
GetAncestor<T>(INode)
Gets the first ancestor node that is of the specified type.
public static T? GetAncestor<T>(this INode node) where T : INode
Parameters
node
INodeThe child of the potential ancestor.
Returns
- T
The specified ancestor or its default value.
Type Parameters
T
GetAncestors(INode)
Gets the ancestor nodes of the provided node, in tree order.
public static IEnumerable<INode> GetAncestors(this INode node)
Parameters
node
INodeThe child of the ancestors.
Returns
- IEnumerable<INode>
An iterator over all ancestors.
GetAssignedSlot(IShadowRoot, string?)
Gets the assigned slot given by the shadow root and the slot name.
public static IElement? GetAssignedSlot(this IShadowRoot root, string? name)
Parameters
root
IShadowRootThe shadow tree hosting the slots.
name
stringThe name of the slot to target.
Returns
- IElement
The slot or default slot, if any.
GetAssociatedHost(INode)
Gets the associated host object, if any. This is mostly interesting for the HTML5 template tag.
public static INode? GetAssociatedHost(this INode node)
Parameters
node
INodeThe node that probably has an host object
Returns
- INode
The host object or null.
GetDescendants(INode)
Gets the descendant nodes of the provided parent, in tree order.
public static IEnumerable<INode> GetDescendants(this INode parent)
Parameters
parent
INodeThe parent of the descendants.
Returns
- IEnumerable<INode>
An iterator over all descendants.
GetDescendantsAndSelf(INode)
Gets the descendant nodes and itself of the provided parent, in tree order.
public static IEnumerable<INode> GetDescendantsAndSelf(this INode parent)
Parameters
parent
INodeThe parent of the descendants.
Returns
- IEnumerable<INode>
An iterator over all descendants and itself.
GetElementCount(INode)
Gets the element count of the given node.
public static int GetElementCount(this INode parent)
Parameters
parent
INodeThe parent of potential element nodes.
Returns
- int
The number of element nodes in the parent.
GetInclusiveAncestors(INode)
Gets the inclusive ancestor nodes of the provided node, in tree order.
public static IEnumerable<INode> GetInclusiveAncestors(this INode node)
Parameters
node
INodeThe child of the ancestors.
Returns
- IEnumerable<INode>
An iterator over all ancestors including the given node.
GetRoot(INode)
Gets the root of the given node, which is the node itself, if it has no parent, or the root of the parent.
public static INode GetRoot(this INode node)
Parameters
node
INodeThe node to get the root of.
Returns
- INode
The root node.
HasDataListAncestor(INode)
Checks if any parent is an HTML datalist element..
public static bool HasDataListAncestor(this INode child)
Parameters
child
INodeThe node to use as starting point.
Returns
- bool
True if a datalist element is among the ancestors, otherwise false.
HasTextNodes(INode)
Checks if the node has any text node children.
public static bool HasTextNodes(this INode node)
Parameters
node
INodeThe parent of the potential text nodes.
Returns
- bool
True if the node has any text nodes, otherwise false.
HyperReference(INode, string)
Gets the hyperreference of the given URL - transforming the given (relative) URL to an absolute URL if required.
public static Url? HyperReference(this INode node, string url)
Parameters
Returns
- Url
The absolute URL.
Index(INode)
Gets the index of the provided node in the parent's collection.
public static int Index(this INode node)
Parameters
node
INodeThe node which needs to know its index.
Returns
- int
The index of the node or -1 if the node is not a child of a parent.
Index(IEnumerable<INode>, INode)
Gets the index of the given item in the list of nodes.
public static int Index(this IEnumerable<INode> nodes, INode item)
Parameters
nodes
IEnumerable<INode>The source list of nodes.
item
INodeThe item to search for.
Returns
- int
The index of the item or -1 if not found.
IndexOf(INode, INode)
Finds the index of the given node of the provided parent node.
public static int IndexOf(this INode parent, INode node)
Parameters
Returns
- int
The node's index or -1 if the node is not a child of the parent.
IsAncestorOf(INode, INode)
Checks if the parent is an ancestor of the given node.
public static bool IsAncestorOf(this INode parent, INode node)
Parameters
Returns
- bool
True if the given parent is actually an ancestor of the node.
IsDescendantOf(INode, INode)
Checks if the node is an descendant of the given parent.
public static bool IsDescendantOf(this INode node, INode parent)
Parameters
Returns
- bool
True if the given parent is actually an ancestor of the node.
IsEndPoint(INode)
Checks if the provided node is an endpoint, i.e., does not host any other node.
public static bool IsEndPoint(this INode node)
Parameters
node
INodeThe node that is checked.
Returns
- bool
True if the node is an endpoint, otherwise false.
IsFollowedByDoctype(INode?)
Checks if the given child is followed by a document type.
public static bool IsFollowedByDoctype(this INode? child)
Parameters
child
INodeThe child that precedes the doctype.
Returns
- bool
True if a doctype node is following the child, otherwise false.
IsFollowing(INode, INode)
Checks if the context node is after the provided node.
public static bool IsFollowing(this INode after, INode before)
Parameters
Returns
- bool
True if the context node is following the ref node in tree order.
IsHostIncludingInclusiveAncestor(INode, INode)
Checks for an inclusive ancestor relationship or if the host (if any) has such a relationship.
public static bool IsHostIncludingInclusiveAncestor(this INode parent, INode node)
Parameters
Returns
- bool
True if the given parent is actually an inclusive ancestor (including the host) of the provided node.
IsInclusiveAncestorOf(INode, INode)
Checks if the parent is an inclusive ancestor of the given node.
public static bool IsInclusiveAncestorOf(this INode parent, INode node)
Parameters
Returns
- bool
True if the given parent is actually an inclusive ancestor of the provided node.
IsInclusiveDescendantOf(INode, INode)
Checks if the node is an inclusive descendant of the given parent.
public static bool IsInclusiveDescendantOf(this INode node, INode parent)
Parameters
Returns
- bool
True if the given parent is actually an inclusive ancestor of the provided node.
IsInsertable(INode)
Checks if the provided node can be inserted into some other node. This excludes, e.g., documents from being inserted.
public static bool IsInsertable(this INode node)
Parameters
node
INodeThe node that is checked.
Returns
- bool
True if the node is insertable, otherwise false.
IsPrecededByElement(INode)
Checks if the given child is preceded by an element node.
public static bool IsPrecededByElement(this INode child)
Parameters
child
INodeThe child that follows any element.
Returns
- bool
True if an element node is preceded the child, otherwise false.
IsPreceding(INode, INode)
Checks if the context node is before the provided node.
public static bool IsPreceding(this INode before, INode after)
Parameters
Returns
- bool
True if the context node is preceding the ref node in tree order.
IsSiblingOf(INode, INode)
Checks if the current node is a sibling of the specified element.
public static bool IsSiblingOf(this INode node, INode element)
Parameters
Returns
- bool
True if the parent is actually non-null and actually the same.
PreInsert(INode, INode, INode?)
Pre-inserts the given node at the parent before the provided child.
public static INode PreInsert(this INode parent, INode node, INode? child)
Parameters
parent
INodeThe origin that will be mutated.
node
INodeThe node to be inserted.
child
INodeThe reference node of the insertation.
Returns
- INode
The inserted node, which is node.
PreRemove(INode, INode)
Pre-removes the given child of the parent.
public static INode PreRemove(this INode parent, INode child)
Parameters
Returns
- INode
The removed node, which is child.
Text(INode)
Gets the content text of the given DOM node.
public static string Text(this INode node)
Parameters
node
INodeThe node to stringify.
Returns
- string
The text of the node and its children.
Text<T>(T, string)
Sets the text content of the given elements.
public static T Text<T>(this T nodes, string text) where T : IEnumerable<INode>
Parameters
nodes
TThe collection.
text
stringThe text that should be set.
Returns
- T
The collection itself.
Type Parameters
T
The type of collection.