XmlSyntaxNode Class

The base of every node in an XML tree.

public abstract class XmlSyntaxNode : SyntaxNode

Example

var tree = XmlSyntaxTree.ParseText("<root><item /></root>");

var kinds = new List<SyntaxKind>();
foreach (var node in tree.GetRoot().DescendantNodes())
{
    kinds.Add(node.Kind());
}

Assert.Equal([SyntaxKind.XmlElement, SyntaxKind.XmlElementStartTag, SyntaxKind.XmlEmptyElement, SyntaxKind.XmlElementEndTag], kinds);
Inheritance
SyntaxNode XmlSyntaxNode

Properties

NameDescription
ParentGets the node this one is a child of, or null when it is the root of its tree.

Gets the node this one is a child of, or null when it is the root of its tree.

public XmlSyntaxNode? Parent { get; }

Property value

XmlSyntaxNode?

Methods

NameDescription
Accept(XmlSyntaxVisitor)Calls the method of visitor that matches this node.
Accept<TResult>(XmlSyntaxVisitor<TResult>)Calls the method of visitor that matches this node.
CreateNavigator()Returns an XPath view of the document this node belongs to, or of this node when it is detached.
Kind()Gets what kind of node this is.
SelectNodes(string)
SelectNodes(string, IXmlNamespaceResolver?)
SelectSingleNode(string)
SelectSingleNode(string, IXmlNamespaceResolver?)
SelectSingleSyntaxNode(string)
SelectSingleSyntaxNode(string, IXmlNamespaceResolver?)
SelectSyntaxNodes(string)
SelectSyntaxNodes(string, IXmlNamespaceResolver?)

Accept overloads

Accept(XmlSyntaxVisitor)

Calls the method of visitor that matches this node.

public abstract void Accept(XmlSyntaxVisitor visitor)
Parameters
visitor XmlSyntaxVisitor
Exceptions
ArgumentNullException
visitor is null.

Accept<TResult>(XmlSyntaxVisitor<TResult>)

Calls the method of visitor that matches this node.

public abstract TResult? Accept<TResult>(XmlSyntaxVisitor<TResult> visitor)
Type parameters
TResult
Parameters
visitor XmlSyntaxVisitor<TResult>
Returns

TResult?

Exceptions
ArgumentNullException
visitor is null.

CreateNavigator()

XmlSyntaxNode.cs

Returns an XPath view of the document this node belongs to, or of this node when it is detached.

public virtual XPathNavigator CreateNavigator()

Gets what kind of node this is.

public SyntaxKind Kind()

Returns

SyntaxKind

SelectNodes overloads

SelectNodes(string)

XmlSyntaxNode.cs
public IEnumerable<XPathNavigator> SelectNodes(string xpath)
Parameters
xpath string
Returns

IEnumerable<XPathNavigator>

Exceptions
ArgumentNullException
xpath is null.

SelectNodes(string, IXmlNamespaceResolver?)

XmlSyntaxNode.cs
public virtual IEnumerable<XPathNavigator> SelectNodes(string xpath, IXmlNamespaceResolver? namespaceResolver)
Parameters
xpath string
namespaceResolver IXmlNamespaceResolver?
Returns

IEnumerable<XPathNavigator>

Exceptions
ArgumentNullException
xpath is null.

SelectSingleNode overloads

SelectSingleNode(string)

XmlSyntaxNode.cs
public XPathNavigator? SelectSingleNode(string xpath)
Parameters
xpath string
Returns

XPathNavigator?

Exceptions
ArgumentNullException
xpath is null.

SelectSingleNode(string, IXmlNamespaceResolver?)

XmlSyntaxNode.cs
public XPathNavigator? SelectSingleNode(string xpath, IXmlNamespaceResolver? namespaceResolver)
Parameters
xpath string
namespaceResolver IXmlNamespaceResolver?
Returns

XPathNavigator?

Exceptions
ArgumentNullException
xpath is null.

SelectSingleSyntaxNode overloads

SelectSingleSyntaxNode(string)

XmlSyntaxNode.cs
public XmlSyntaxNode? SelectSingleSyntaxNode(string xpath)
Parameters
xpath string
Returns

XmlSyntaxNode?

Exceptions
ArgumentNullException
xpath is null.

SelectSingleSyntaxNode(string, IXmlNamespaceResolver?)

XmlSyntaxNode.cs
public XmlSyntaxNode? SelectSingleSyntaxNode(string xpath, IXmlNamespaceResolver? namespaceResolver)
Parameters
xpath string
namespaceResolver IXmlNamespaceResolver?
Returns

XmlSyntaxNode?

Exceptions
ArgumentNullException
xpath is null.

SelectSyntaxNodes overloads

SelectSyntaxNodes(string)

XmlSyntaxNode.cs
public IEnumerable<XmlSyntaxNode> SelectSyntaxNodes(string xpath)
Parameters
xpath string
Returns

IEnumerable<XmlSyntaxNode>

Exceptions
ArgumentNullException
xpath is null.

SelectSyntaxNodes(string, IXmlNamespaceResolver?)

XmlSyntaxNode.cs
public IEnumerable<XmlSyntaxNode> SelectSyntaxNodes(string xpath, IXmlNamespaceResolver? namespaceResolver)
Parameters
xpath string
namespaceResolver IXmlNamespaceResolver?
Returns

IEnumerable<XmlSyntaxNode>

Exceptions
ArgumentNullException
xpath is null.