Xml – How to Retrieve XML Node Attributes In C#

xml

how to navigate the XML file and get all a list of nodes in order to access their attributes and count no of nodes in Student tag.

for example :

Can anybody briefy me .how to do ? give any sample code to do so.?

Best Solution

You can get a collection of XmlNodes from and XmlDocument like this

XmlNodeList nodes = document.GetElementsByTagName("MyNodeName");
foreach (XmlNode node in nodes)
{
    // do stuff with each node
}

The XmlNode class has an Attributes property which is a collection of attributes. You can iterate through them and match the attributes you are looking for.