From the course: Complete Guide to .NET LINQ: Querying Collections, Databases, and Markup

Unlock this course with a free trial

Join today to access over 24,700 courses taught by industry experts.

Query attributes in XML

Query attributes in XML

- [Instructor] We can query a collection of attributes too. In this example, it is the attributes method that serves as the query source, and that's because it returns an IEnumerable of X attribute. So let's see what this first query is doing. I'm creating a query expression from ATT and collectibles elements. So I'm getting the one element, the card elements, just a single card, and then all of its attributes. So what I'm doing first is I'm printing out the card itself to remind ourselves of what are the attributes. There's five of them and then here I can see in my IEnumerable of x attribute those five items. Now notice I'm getting back the name value pair. This is the attribute name, this is the value. And again, they're all string values. The second example, I'm getting all the elements, all the cards, and all the attributes. So now I get 35 items back. This is a rich data source. I can then start doing more queries on this or using query operators like order by. I could use a…

Contents