Gets the number of attributes on the current node.
using System;
using System.IO;
using System.Xml;
public class Sample {
public static void Main() {
string xmlData =
@"<book>
<title>C#</title>
<price>5.95</price>
</book>";
XmlTextReader reader = new XmlTextReader(new StringReader(xmlData));
if (reader.HasAttributes)
{
Console.WriteLine("Attributes of <" + reader.Name + ">");
for (int i = 0; i < reader.AttributeCount; i++)
{
reader.MoveToAttribute(i);
Console.Write(" {0}={1}", reader.Name, reader.Value);
}
reader.MoveToElement(); //Moves the reader back to the element node.
}
}
}
Related examples in the same category