XLINQ blows my mind

Just spent a couple of hours setting up a couple of VPC images with all "The Goods" we got from PDC'05. Last thing I installed was the LINQ tech preview. I've just spent a few minutes looking at the LINQ samples that comes on disk 4 and I've tried a few DLINQ stuff which was really impressive, but the XLINQ features just blows my mind. The whole style of programming seems so natural compared to the old XmlDocument way of doing things. Let me copy a few lines of code from the RssAggregator sample, a method which pulls Rss from a couple of feeds, extracts the items and returns a list of all these items:

static IEnumerable<XElement> GetItems() {

string[] feeds = {

"http://blogs.msdn.com/cyrusn/rss.aspx",

"http://blogs.msdn.com/mattwar/rss.aspx",

"http://blogs.msdn.com/lucabol/rss.aspx",

"http://www.pluralsight.com/blogs/dbox/rss.aspx",

"http://blogs.msdn.com/jomo_fisher/rss.aspx"

};

foreach (var str in feeds) {

var feed = XDocument.Load(str);

var items = feed.Root.Element("channel").Elements("item");

foreach (var item in items)

yield return item;

}

}

I love the way you get hold of a specific element in the document with Element("nodename"). Not sure I'm comfortable with the "var" thing though. That's the "implicitly typed local variables" that comes with C# 3.0. I guess it's the way I read code. If you want to read about the new features in C# 3.0, you can download the spec from here.

1 Comment

Comments have been disabled for this content.