The XDocument.Load(path) static method supports the ability open both XML files from the file-system, as well as remote XML feeds
returned from an HTTP URL. This enables you to use it to access remote RSS
feeds, REST APIs, as well as any other XML feed published on the web.
For an example of this in action, let's take a look at the
XML of my blog's RSS feed (http://weblogs.asp.net/scottgu/rss.aspx):
Figure 10
I could write the LINQ to XML code below to
retrieve the above blog post data from my RSS feed, and work with the
individual feed items as .NET objects:
Figure 11
Note above how I am converting the
"Published" field in the RSS field - which is a string in the
XML - to a .NET DateTime object. Notice also how LINQ to XML
includes a built-in XNamespace type that provides a type-safe way to declare
and work with XML Namespaces (which I need to-do to retrieve the
<slash:comments> element).
I could then take advantage of the composition
features of LINQ to perform a further sub-query on the result, so that I filter
over only those RSS posts that were published within the last 7 days using the
code below:
Figure 12
As you can see above, you can feed the results
of one LINQ query expression to be the input of another LINQ
expression. This enables you to write very clean, highly
composable, code.