From the course: .NET Essentials: LINQ for XML

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Get attributes

Get attributes - .NET Tutorial

From the course: .NET Essentials: LINQ for XML

Start my 1-month free trial

Get attributes

- [Instructor] An element can have 0 or more attributes, so there has to be a way of getting a single attribute, or a collection of attributes and this is the syntax for that. If you want a single attribute, you call .attribute and you provide the name, and you get the attribute value, the name value pair back. If you want to get the IEnumerable Xattribute you call attributes, this will return all of the attributes that are in this element. Here it has five items: card name, team name, rarity, collector number and card family. This also works when you're working with IEnumerables of elements. So let's change this top line here and say I want elements. So I want all the elements, all cards, there's 7 of them. And then I want all the attributes that are on all the cards. So now when I run this, I get back 35 items in this IEnumerable.

Contents