Node Class

https://dom.spec.whatwg.org/#interface-node

public abstract class Node : EventTarget, IXPathNSResolver, IXPathNavigable
Inheritance
EventTarget Node
Implements

Properties

NameDescription
BaseUrihttps://dom.spec.whatwg.org/#dom-node-baseuri
ChildNodesGets the live list of the children of the node.
FirstChildGets the first child of the node, or null.
IsConnectedGets a value indicating whether the shadow-including root of the node is a document.
LastChildGets the last child of the node, or null.
NextSiblingGets the next sibling of the node, or null.
NodeNameGets the name of the node, which depends on its type.
NodeTypeGets the type of the node, one of the node type constants.
NodeValueGets or sets the value of the node: the data of the character data nodes and attributes, null for the other nodes.
OwnerDocumentGets the document that owns the node, or null when the node is a document.
ParentElementGets the parent of the node when it is an element; otherwise null.
ParentNodeGets the parent of the node, or null.
PreviousSiblingGets the previous sibling of the node, or null.
TextContentGets or sets the text content of the node and its descendants.

BaseUri

Node.cs

https://dom.spec.whatwg.org/#dom-node-baseuri

public string BaseUri { get; }

ChildNodes

Node.cs

Gets the live list of the children of the node.

public NodeList ChildNodes { get; }

FirstChild

Node.cs

Gets the first child of the node, or null.

public Node? FirstChild { get; }

IsConnected

Node.cs

Gets a value indicating whether the shadow-including root of the node is a document.

public bool IsConnected { get; }

LastChild

Node.cs

Gets the last child of the node, or null.

public Node? LastChild { get; }

NextSibling

Node.cs

Gets the next sibling of the node, or null.

public Node? NextSibling { get; }

NodeName

Gets the name of the node, which depends on its type.

public abstract string NodeName { get; }

NodeType

Gets the type of the node, one of the node type constants.

public abstract ushort NodeType { get; }

NodeValue

Node.cs

Gets or sets the value of the node: the data of the character data nodes and attributes, null for the other nodes.

public virtual string? NodeValue { get; set; }

OwnerDocument

Node.cs

Gets the document that owns the node, or null when the node is a document.

public Document? OwnerDocument { get; }

ParentElement

Node.cs

Gets the parent of the node when it is an element; otherwise null.

public Element? ParentElement { get; }

ParentNode

Node.cs

Gets the parent of the node, or null.

public Node? ParentNode { get; }

PreviousSibling

Node.cs

Gets the previous sibling of the node, or null.

public Node? PreviousSibling { get; }

TextContent

Node.cs

Gets or sets the text content of the node and its descendants.

public virtual string? TextContent { get; set; }

Methods

NameDescription
Ancestors()Enumerates the ancestors of this node, from the parent to the root. The enumeration is lazy and does not cross shadow roots.
Ancestors<T>()Enumerates the ancestors of this node of type T, from the parent to the root. The enumeration is lazy and does not cross shadow roots.
AncestorsAndSelf()Enumerates this node and its ancestors, from this node to the root (the inclusive ancestors). The enumeration is lazy and does not cross shadow roots.
AncestorsAndSelf<T>()Enumerates this node and its ancestors of type T, from this node to the root. The enumeration is lazy and does not cross shadow roots.
AppendChild(Node)Inserts the node after the last child and returns it.
CloneNode(bool)https://dom.spec.whatwg.org/#dom-node-clonenode
CompareDocumentPosition(Node)https://dom.spec.whatwg.org/#dom-node-comparedocumentposition
Contains(Node?)https://dom.spec.whatwg.org/#dom-node-contains
CreateNavigator()Creates a read-only XPathNavigator positioned on this node, to use the .NET XPath and XSLT APIs over the DOM (the XPath 1.0 data model: adjacent text nodes are merged, doctypes are ignored).
Descendants()Enumerates the descendants of this node in tree order. The enumeration is lazy.
Descendants<T>()Enumerates the descendants of this node of type T, in tree order. The enumeration is lazy.
DescendantsAndSelf()Enumerates this node and its descendants in tree order (the inclusive descendants). The enumeration is lazy.
DescendantsAndSelf<T>()Enumerates this node and its descendants of type T, in tree order. The enumeration is lazy.
GetRootNode(GetRootNodeOptions?)Returns the root of the tree that contains the node, or its shadow-including root when composed is set.
HasChildNodes()Returns whether the node has at least one child.
InsertBefore(Node, Node?)Inserts the node before the given child (or after the last child when it is null) and returns it.
IsDefaultNamespace(string?)https://dom.spec.whatwg.org/#dom-node-isdefaultnamespace
IsEqualNode(Node?)https://dom.spec.whatwg.org/#dom-node-isequalnode
IsSameNode(Node?)Returns whether the given node is this node.
LookupNamespaceUri(string?)https://dom.spec.whatwg.org/#dom-node-lookupnamespaceuri
LookupPrefix(string?)https://dom.spec.whatwg.org/#dom-node-lookupprefix
Normalize()https://dom.spec.whatwg.org/#dom-node-normalize
RemoveChild(Node)Removes the child and returns it.
ReplaceChild(Node, Node)Replaces the child with the node and returns the replaced child.
ToHtml(HtmlFormatter?)Returns the markup of the node, formatted by formatter (HtmlFormatter.Default when null): an element with its start tag, its descendants and its end tag (as Element.OuterHtml), the children of a document or a document fragment.
ToHtml(TextWriter, HtmlFormatter?)Same as Node.ToHtml, but writes the markup to output instead of building a string.

Ancestors overloads

Ancestors()

Node.cs

Enumerates the ancestors of this node, from the parent to the root. The enumeration is lazy and does not cross shadow roots.

public IEnumerable<Node> Ancestors()

Ancestors<T>()

Node.cs

Enumerates the ancestors of this node of type T, from the parent to the root. The enumeration is lazy and does not cross shadow roots.

public IEnumerable<T> Ancestors<T>() where T : Node
Type parameters
T
Returns

IEnumerable<T>

AncestorsAndSelf overloads

AncestorsAndSelf()

Node.cs

Enumerates this node and its ancestors, from this node to the root (the inclusive ancestors). The enumeration is lazy and does not cross shadow roots.

public IEnumerable<Node> AncestorsAndSelf()

AncestorsAndSelf<T>()

Node.cs

Enumerates this node and its ancestors of type T, from this node to the root. The enumeration is lazy and does not cross shadow roots.

public IEnumerable<T> AncestorsAndSelf<T>() where T : Node
Type parameters
T
Returns

IEnumerable<T>

AppendChild(Node)

Node.cs

Inserts the node after the last child and returns it.

public Node AppendChild(Node node)

CloneNode(bool)

Node.cs

https://dom.spec.whatwg.org/#dom-node-clonenode

public Node CloneNode(bool subtree = false)

CompareDocumentPosition(Node)

Node.cs

https://dom.spec.whatwg.org/#dom-node-comparedocumentposition

public ushort CompareDocumentPosition(Node other)

Contains(Node?)

Node.cs

https://dom.spec.whatwg.org/#dom-node-contains

public bool Contains(Node? other)

CreateNavigator()

Node.XPath.cs

Creates a read-only XPathNavigator positioned on this node, to use the .NET XPath and XSLT APIs over the DOM (the XPath 1.0 data model: adjacent text nodes are merged, doctypes are ignored).

public XPathNavigator CreateNavigator()

Descendants overloads

Descendants()

Node.cs

Enumerates the descendants of this node in tree order. The enumeration is lazy.

public IEnumerable<Node> Descendants()

Descendants<T>()

Node.cs

Enumerates the descendants of this node of type T, in tree order. The enumeration is lazy.

public IEnumerable<T> Descendants<T>() where T : Node
Type parameters
T
Returns

IEnumerable<T>

DescendantsAndSelf overloads

DescendantsAndSelf()

Node.cs

Enumerates this node and its descendants in tree order (the inclusive descendants). The enumeration is lazy.

public IEnumerable<Node> DescendantsAndSelf()

DescendantsAndSelf<T>()

Node.cs

Enumerates this node and its descendants of type T, in tree order. The enumeration is lazy.

public IEnumerable<T> DescendantsAndSelf<T>() where T : Node
Type parameters
T
Returns

IEnumerable<T>

GetRootNode(GetRootNodeOptions?)

Node.cs

Returns the root of the tree that contains the node, or its shadow-including root when composed is set.

public Node GetRootNode(GetRootNodeOptions? options = null)

HasChildNodes()

Node.cs

Returns whether the node has at least one child.

public bool HasChildNodes()

InsertBefore(Node, Node?)

Node.cs

Inserts the node before the given child (or after the last child when it is null) and returns it.

public Node InsertBefore(Node node, Node? child)

IsDefaultNamespace(string?)

Node.cs

https://dom.spec.whatwg.org/#dom-node-isdefaultnamespace

public bool IsDefaultNamespace(string? @namespace)

IsEqualNode(Node?)

Node.cs

https://dom.spec.whatwg.org/#dom-node-isequalnode

public bool IsEqualNode(Node? otherNode)

IsSameNode(Node?)

Node.cs

Returns whether the given node is this node.

public bool IsSameNode(Node? otherNode)

LookupNamespaceUri(string?)

Node.cs

https://dom.spec.whatwg.org/#dom-node-lookupnamespaceuri

public string? LookupNamespaceUri(string? prefix)

LookupPrefix(string?)

Node.cs

https://dom.spec.whatwg.org/#dom-node-lookupprefix

public string? LookupPrefix(string? @namespace)

Normalize()

Node.cs

https://dom.spec.whatwg.org/#dom-node-normalize

public void Normalize()

RemoveChild(Node)

Node.cs

Removes the child and returns it.

public Node RemoveChild(Node child)

ReplaceChild(Node, Node)

Node.cs

Replaces the child with the node and returns the replaced child.

public Node ReplaceChild(Node node, Node child)

ToHtml overloads

ToHtml(HtmlFormatter?)

Node.Formatting.cs

Returns the markup of the node, formatted by formatter (HtmlFormatter.Default when null): an element with its start tag, its descendants and its end tag (as Element.OuterHtml), the children of a document or a document fragment.

public string ToHtml(HtmlFormatter? formatter = null)
Parameters
formatter HtmlFormatter?
Returns

string

ToHtml(TextWriter, HtmlFormatter?)

Node.Formatting.cs

Same as Node.ToHtml, but writes the markup to output instead of building a string.

public void ToHtml(TextWriter output, HtmlFormatter? formatter = null)
Parameters
output TextWriter
formatter HtmlFormatter?

Constants

NameDescription
AttributeNodeThe node type of an attribute.
CDataSectionNodeThe node type of a CDATA section.
CommentNodeThe node type of a comment.
DocumentFragmentNodeThe node type of a document fragment.
DocumentNodeThe node type of a document.
DocumentPositionContainedByThe bit set by compareDocumentPosition() when the other node is a descendant of the node.
DocumentPositionContainsThe bit set by compareDocumentPosition() when the other node is an ancestor of the node.
DocumentPositionDisconnectedThe bit set by compareDocumentPosition() when the nodes are not in the same tree.
DocumentPositionFollowingThe bit set by compareDocumentPosition() when the other node follows the node.
DocumentPositionImplementationSpecificThe bit set by compareDocumentPosition() when the order of the disconnected nodes is implementation- specific.
DocumentPositionPrecedingThe bit set by compareDocumentPosition() when the other node precedes the node.
DocumentTypeNodeThe node type of a document type.
ElementNodeThe node type of an element.
EntityNodeThe legacy node type of an entity (never created).
EntityReferenceNodeThe legacy node type of an entity reference (never created).
NotationNodeThe legacy node type of a notation (never created).
ProcessingInstructionNodeThe node type of a processing instruction.
TextNodeThe node type of a text node.

AttributeNode

The node type of an attribute.

public const ushort AttributeNode = 2

CDataSectionNode

The node type of a CDATA section.

public const ushort CDataSectionNode = 4

CommentNode

The node type of a comment.

public const ushort CommentNode = 8

DocumentFragmentNode

The node type of a document fragment.

public const ushort DocumentFragmentNode = 11

DocumentNode

The node type of a document.

public const ushort DocumentNode = 9

DocumentPositionContainedBy

The bit set by compareDocumentPosition() when the other node is a descendant of the node.

public const ushort DocumentPositionContainedBy = 16

DocumentPositionContains

The bit set by compareDocumentPosition() when the other node is an ancestor of the node.

public const ushort DocumentPositionContains = 8

DocumentPositionDisconnected

The bit set by compareDocumentPosition() when the nodes are not in the same tree.

public const ushort DocumentPositionDisconnected = 1

DocumentPositionFollowing

The bit set by compareDocumentPosition() when the other node follows the node.

public const ushort DocumentPositionFollowing = 4

DocumentPositionImplementationSpecific

The bit set by compareDocumentPosition() when the order of the disconnected nodes is implementation- specific.

public const ushort DocumentPositionImplementationSpecific = 32

DocumentPositionPreceding

The bit set by compareDocumentPosition() when the other node precedes the node.

public const ushort DocumentPositionPreceding = 2

DocumentTypeNode

The node type of a document type.

public const ushort DocumentTypeNode = 10

ElementNode

The node type of an element.

public const ushort ElementNode = 1

EntityNode

The legacy node type of an entity (never created).

public const ushort EntityNode = 6

EntityReferenceNode

The legacy node type of an entity reference (never created).

public const ushort EntityReferenceNode = 5

NotationNode

The legacy node type of a notation (never created).

public const ushort NotationNode = 12

ProcessingInstructionNode

The node type of a processing instruction.

public const ushort ProcessingInstructionNode = 7

TextNode

The node type of a text node.

public const ushort TextNode = 3