This should work, assuming feed.Items is strongly typed.

1
2
3
4
5
public static List<string> GetAtomFeed(string url) {
    XmlReader reader = XmlReader.Create(url);
    SyndicationFeed feed = SyndicationFeed.Load<SyndicationFeed>(reader);
    return feed.Items.Select(i => i.Links[1].Uri.ToString()).ToList()
}
By on 4/19/2009 9:55 PM ()

I was hoping that the answer to my question might point me to

something I needed to learn. I've

searched my C# 3 book, and found that Select statement in Linq. So,

looks like I need to work out a bit of Linq, and how that works with

the ServiceModel.SyndicationFeed class.

I'm also curious to find out whether the F# original is using Linq. It's on my to do list, and I'll post back here.

Thanks again, Michael.

By on 4/20/2009 12:37 AM ()

Looking at it like this, LINQ is similar to what is inside the Seq module. Seq.filter = IEnumerable.Where. Seq.map = IEnumerable.Select. And so on. The difference is that C# gets the nice syntax via extension methods instead of pipelines and modules.

By on 4/20/2009 6:39 AM ()

@Michael:

>> Looking at it like this, LINQ is similar to what is inside the Seq

module. Seq.filter = IEnumerable.Where. Seq.map = IEnumerable.Select.

>> And so on. The difference is that C# gets the nice syntax via extension

methods instead of pipelines and modules.

Thanks again Michael.

Inspired by this comparison, I spent an afternoon delving more into Linq, and discovered the joy of chaining the operations.

For my app I had to do a regexp replace on part of the atom feed. With Linq, it turns out very neatly...

1
2
3
4
5
            
response.photoUrls = 
                feed.Items.Select(item => item.Links[1].Uri.ToString()).
                Select(s => Regex.Replace(s, "size:medium", "size:small")).
                ToList();

The overall solution, with WCF (ServiceModel) and Linq is much better than traditional C#.

I've also done an atom reader in PHP. After looking at the PHP atom "helper" classes, I decided to just use a file read, and sequential string reading and searching!

By on 4/21/2009 8:57 PM ()

Yup! Nice work - thankyou.

>> assuming feed.Items is strongly typed

Yes. In fact, it was very nice using this to process the feed, as I used intellisense to pick the component I needed (item.Links).

By on 4/19/2009 11:11 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper