MSDN Documentation

Name Property

Gets the name of the current node.

Syntax

public override string Name { get; }

Returns

A String that contains the name of the node. For any node types other than XmlNodeType.Element, the value may be String.Empty.

Remarks

The Name property reflects the node name from the underlying XmlNode that the XmlNodeReader was created from. This value is read‑only and cannot be modified through the reader.

Typical use cases include:

Example

using System;
using System.Xml;

class Program
{
    static void Main()
    {
        string xml = @"
        <bookstore>
            <book genre='autobiography'>
                <title>The Autobiography of Benjamin Franklin</title>
                <author>Benjamin Franklin</author>
                <price>8.99</price>
            </book>
        </bookstore>";

        XmlDocument doc = new XmlDocument();
        doc.LoadXml(xml);

        using (XmlNodeReader reader = new XmlNodeReader(doc))
        {
            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    Console.WriteLine($""Element: {reader.Name}"");
                }
            }
        }
    }
}

See Also