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 - .NET Tutorial
From the course: .NET Essentials: LINQ for XML
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
-
-
-
-
-
(Locked)
Use Query syntax to work with elements2m 46s
-
(Locked)
Attribute query1m 27s
-
(Locked)
Select data into a new anonymous type1m 47s
-
(Locked)
Where clause on attribute value1m 53s
-
(Locked)
Where clause with compare2m 11s
-
(Locked)
Aggregate queries2m 1s
-
(Locked)
Choose output order with OrderBy42s
-
(Locked)
Query for empty elements and blank values3m 21s
-
(Locked)
Group by3m 26s
-
(Locked)
Challenge: Create custom string output1m 46s
-
(Locked)
Solution: Create custom string output1m 14s
-
(Locked)
Challenge: Filter results to show elements with no content47s
-
(Locked)
Solution: Filter results to show elements with no content55s
-
(Locked)
Challenge: Filter results to show invalid values1m 39s
-
(Locked)
Solution: Filter results to show invalid values1m 53s
-
(Locked)
-
-