Feed Synchronization one liner

One of the things that troubled me for quite a long time now was the fact that my RSS feeds were out of sync between my home and work PCs. That’s because I kept forgetting to add the feeds I was subscribing from one PC to the other. And of course I didn’t want to delete all feeds from either one of them cause that could result in loosing some.

I had to build a small utility that, using XML DOM and XPath, would read my aggregators’ OPML files and synchronize them. The problem was that I didn’t have time for such a program.

With Linq to XML though things got a lot easier, so much easier that I can now write a single line of code that will find out which feed subscriptions are not contained from an OPML file to another like so:

var feedQuery = 
    from f in XElement.Load("subset.opml").Descendants("outline")
    where f.Attribute("xmlUrl") != null &&
          (from XElement o in XElement.Load("Full.opml").Descendants("outline")
           where o.Attribute("xmlUrl") != null
           select (string)o.Attribute("xmlUrl")).ToList().Contains(((string)f.Attribute("xmlUrl")))
    select f;

So I’m finally going to have all my feeds synced ….

 
Comments

No comments yet.

Leave a Reply