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
From the course: Complete Guide to .NET LINQ: Querying Collections, Databases, and Markup
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
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
(Locked)
Use Query syntax to work with elements4m 59s
-
(Locked)
Query element values in XML1m 10s
-
(Locked)
Query attributes in XML1m 56s
-
(Locked)
Project data into an anonymous type4m 10s
-
(Locked)
Filter by attribute value with Where1m 52s
-
(Locked)
Use Where to compare values2m 10s
-
(Locked)
Perform aggregate queries in XML1m 26s
-
(Locked)
Sort query results with OrderBy3m 29s
-
(Locked)
Find empty elements and blank values4m 51s
-
(Locked)
Group XML data with GroupBy3m 48s
-
(Locked)
Challenge: Create a custom string output1m 50s
-
(Locked)
Solution: Create a custom string output1m 19s
-
(Locked)
Challenge: Filter elements with no content52s
-
(Locked)
Solution: Filter elements with no content51s
-
(Locked)
Challenge: Filter results for invalid values1m 28s
-
(Locked)
Solution: Filter results for invalid values1m 54s
-
(Locked)
-
-