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.

Attribute query

Attribute query - .NET Tutorial

From the course: .NET Essentials: LINQ for XML

Start my 1-month free trial

Attribute query

- [Instructor] We can use the attributes method to serve as this data source for our queries. Remember that it returns an IEnumerable of XAttribute, so this allows us to query the information that's in our attribute values. I'll show you what's in the file to start with. So I'll run this code, and this shows the seven cards that are in our XML file. And this first card has five attributes, card name, team name, rarity, collector number, and card family. Let's come in at line 10, and look at the query that I wrote. So we started off with the query expression from att in collectibles, elements, we're getting the "Card" element. And then I'm calling attributes, that's the collection or the IEnumerable that we're querying on the single card. This returns one card, remember. So that this is querying just the attributes on this first card. Then I say, select att, and that gives me five items. Now if you want to get all…

Contents