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.
Solution: Create custom string output - .NET Tutorial
From the course: .NET Essentials: LINQ for XML
Solution: Create custom string output
(upbeat electronic music) - I hope you had fun working on this challenge. Here's my results. Remember your solution may be different from mine. You'll find my solution in the CodeChallenges folder. So I start off by loading the XML file. We've seen this in many examples, but here's the code I used to load that example. I stored the root element in this variable called allElements. Then I create my query. I am going to the root element and getting all the elements. Then I'm selecting out the new anonymous type, and I have two properties, ColorName and Formula. The color name is coming from the attribute "color-name." And then the formula is, basically, a interpolated string. So I have the string that I want. Let's see what it looks like when I show the results. I don't like that, I'll run it again. So I have this string and I'm just ticking this value inside the curly braces. This is where the number 139 is coming from,…
Contents
-
-
-
-
-
Use Query syntax to work with elements2m 46s
-
Attribute query1m 27s
-
Select data into a new anonymous type1m 47s
-
Where clause on attribute value1m 53s
-
Where clause with compare2m 11s
-
Aggregate queries2m 1s
-
Choose output order with OrderBy42s
-
Query for empty elements and blank values3m 21s
-
Group by3m 26s
-
Challenge: Create custom string output1m 46s
-
Solution: Create custom string output1m 14s
-
Challenge: Filter results to show elements with no content47s
-
Solution: Filter results to show elements with no content55s
-
Challenge: Filter results to show invalid values1m 39s
-
Solution: Filter results to show invalid values1m 53s
-
-
-