Using LINQ to XML (and how to build a custom RSS Feed Reader with it)
page 6 of 9
by Scott Guthrie
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 7022/ 175

Using LINQ Sub-Queries within a LINQ to XML Query Expression

If you look at the raw XML of my RSS feed, you'll notice that the "tag" comments for each post are stored as repeated <category> elements directly below each <item> element:

Figure 13

When designing the object model for a "BlogEntry" class, I might want to represent these <category> values as a sub-collection of strings.  For example, using a "Tags" property that is a generic list of type string:

Figure 14

You might be wondering - how do we take a flat collection of <category> elements under <item> and transform them into a nested sub-collection of strings?  The nice thing about LINQ is that it makes this type of scenario easy by allowing us to use nested LINQ query expressions like so:

Figure 15

This "shaping" power of LINQ, and its ability to take flat data structures and make them hierarchical (and take hierarchical data structures and make them flat) is super powerful.  You can use this feature with any type of data source - regardless of whether it is XML, SQL, or plain old objects/arrays/collections.


View Entire Article

Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 5 and 7 and type the answer here:

User Comments

No comments posted yet.






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2008 ASPAlliance.com  |  Page Processed at 10/13/2008 4:46:16 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search