Just sharing some of my inconsequential lunch conversations with you... RSS  

Thursday, December 20, 2007

Using Linq to XML to extract data from... my blog roll!

I read a lot of blogs daily - most of them over breakfast and after dinner. As FeedDemon doesn't allow more than one level of grouping, neither an order, I've prefixed a ordering to the groups I read daily - the other I use through the 'Popular Topics' report.Here's how I've counted the number of daily links:

using (XmlReader reader = new XmlTextReader(@"D:\Users\mario.romano\Documents\RSSs\2007.12.20.opml"))
{
var query =
from outline in XElement.Load(reader).Element("body").Elements("outline").Elements("outline")
where outline.Parent.FirstAttribute.Value.IndexOf(". ") != -1 // the blogs I read daily
orderby outline.Parent.FirstAttribute.Value
group outline by outline.Parent.FirstAttribute.Value into parentOutline
select new
{
Key = parentOutline.Key,
HowMany = parentOutline.Count()
};

foreach (var result in query)
{
Console.WriteLine("{1,4}: {0}", result.Key, result.HowMany);
}
};
I just love Linq! And to get a final count of counts, I just have to:
    Console.WriteLine("{0}", query.Sum(p => p.HowMany));
PS: the results are: 152 feeds read daily, from a total of 430 feeds.
PS2: Yeap, the real reason to post this is to test my new CSS for a large width code :)

[update]
I give up, it works fine on Firefox but looks lousy on IE7. Argh......

[update II]
I've just fixed it for IE. Check it out.

No comments:

Development Catharsis :: Copyright 2006 Mário Romano