public int get_AttributeCount { get; }
int
This property returns the number of attributes associated with the current node. For nodes that do not have attributes (such as elements with no attributes, text nodes, or comments), this property will return 0.
// Assume xmlReader is an initialized XmlReader positioned on an element node
using System.Xml;
public void ProcessNodeAttributes(XmlReader xmlReader)
{
if (xmlReader.NodeType == XmlNodeType.Element)
{
int attributeCount = xmlReader.AttributeCount;
Console.WriteLine($"The current element has {attributeCount} attributes.");
for (int i = 0; i < attributeCount; i++)
{
Console.WriteLine($" Attribute {i + 1}: Name='{xmlReader.GetAttribute(i)}', Value='{xmlReader.GetAttribute(i)}'");
}
}
}