Aggregating Feeds using CompositeCollection - Rudi Grobler

Aggregating Feeds using CompositeCollection

While reading Adam Nathan's WPF Unleashed, I noticed a interesting collection class called CompositeCollection. This effectively allows you to make multiple collections appear as a single collection. To try it out, RSS immediately came to mind. Image I have multiple RSS feeds but want to show all of them in my main view...

A while back I mentioned some WPF blogs I read... I will take each of these blogs feeds and composite it into a single collection (All from XAML)

Here is the separate feeds for Josh Smith, Karl Shifflet, Sacha Barber & Dr WPF

<XmlDataProvider x:Key="DrWPFFeeds" d:IsDataSource="True" Source="http://www.drwpf.com/blog/Home/tabid/36/rssid/1/Default.aspx">
    <XmlDataProvider.XmlNamespaceManager>
        <XmlNamespaceMappingCollection>
            <XmlNamespaceMapping Prefix="trackback" Uri="http://madskills.com/public/xml/rss/module/trackback/"/>
            <XmlNamespaceMapping Prefix="slash" Uri="http://purl.org/rss/1.0/modules/slash/"/>
        </XmlNamespaceMappingCollection>
    </XmlDataProvider.XmlNamespaceManager>
</XmlDataProvider>
<XmlDataProvider x:Key="JoshSmithFeeds" d:IsDataSource="True" Source="http://joshsmithonwpf.wordpress.com/feed/">
    <XmlDataProvider.XmlNamespaceManager>
        <XmlNamespaceMappingCollection>
            <XmlNamespaceMapping Prefix="dc" Uri="http://purl.org/dc/elements/1.1/"/>
            <XmlNamespaceMapping Prefix="atom" Uri="http://www.w3.org/2005/Atom"/>
            <XmlNamespaceMapping Prefix="media" Uri="http://search.yahoo.com/mrss"/>
            <XmlNamespaceMapping Prefix="wfw" Uri="http://wellformedweb.org/CommentAPI/"/>
            <XmlNamespaceMapping Prefix="content" Uri="http://purl.org/rss/1.0/modules/content/"/>
        </XmlNamespaceMappingCollection>
    </XmlDataProvider.XmlNamespaceManager>
</XmlDataProvider>
<XmlDataProvider x:Key="KarlShiffletFeeds" d:IsDataSource="True" Source="http://karlshifflett.wordpress.com/feed/">
    <XmlDataProvider.XmlNamespaceManager>
        <XmlNamespaceMappingCollection>
            <XmlNamespaceMapping Prefix="dc" Uri="http://purl.org/dc/elements/1.1/"/>
            <XmlNamespaceMapping Prefix="atom" Uri="http://www.w3.org/2005/Atom"/>
            <XmlNamespaceMapping Prefix="media" Uri="http://search.yahoo.com/mrss"/>
            <XmlNamespaceMapping Prefix="wfw" Uri="http://wellformedweb.org/CommentAPI/"/>
            <XmlNamespaceMapping Prefix="content" Uri="http://purl.org/rss/1.0/modules/content/"/>
        </XmlNamespaceMappingCollection>
    </XmlDataProvider.XmlNamespaceManager>
</XmlDataProvider>
<XmlDataProvider x:Key="SachaBarberFeeds" d:IsDataSource="True" Source="http://sachabarber.net/?feed=rss2">
    <XmlDataProvider.XmlNamespaceManager>
        <XmlNamespaceMappingCollection>
            <XmlNamespaceMapping Prefix="wfw" Uri="http://wellformedweb.org/CommentAPI/"/>
            <XmlNamespaceMapping Prefix="content" Uri="http://purl.org/rss/1.0/modules/content/"/>
            <XmlNamespaceMapping Prefix="dc" Uri="http://purl.org/dc/elements/1.1/"/>
        </XmlNamespaceMappingCollection>
    </XmlDataProvider.XmlNamespaceManager>
</XmlDataProvider>

PS. These blogs provide excellent material... If you are interested in WPF content you have to subscribe to them!

Next step is to take each of these feeds and composite it into a single collection

<CompositeCollection x:Key="Feeds">
    <CollectionContainer Collection="{Binding Source={StaticResource DrWPFFeeds}, XPath=/rss/channel/item}"/>
    <CollectionContainer Collection="{Binding Source={StaticResource JoshSmithFeeds}, XPath=/rss/channel/item}"/>
    <CollectionContainer Collection="{Binding Source={StaticResource KarlShiffletFeeds}, XPath=/rss/channel/item}"/>
    <CollectionContainer Collection="{Binding Source={StaticResource SachaBarberFeeds}, XPath=/rss/channel/item}"/>
</CompositeCollection>

Now my ListBox can bind to the data source Feeds and all of the separate blogs feeds will appear in one collection!!!

kick it on DotNetKicks.com
Published Wednesday, March 19, 2008 7:52 AM by rudi

Comments

# Aggregating feeds using CompositeCollection

You've been kicked (a good thing) - Trackback from DotNetKicks.com

Wednesday, March 19, 2008 7:54 AM by DotNetKicks.com

# re: Aggregating Feeds using CompositeCollection

Great stuff...

Wednesday, March 19, 2008 5:29 PM by Marlon Grech

# re: Aggregating Feeds using CompositeCollection

I agree with Marlon!  Also, great data... ;)

Wednesday, March 19, 2008 5:33 PM by Josh Smith

# re: Aggregating Feeds using CompositeCollection

Nice use of WPF.  Ummmmm.   This gets me thinking!

Cheers,

Karl

Wednesday, March 19, 2008 6:23 PM by Karl Shifflett

# re: Aggregating Feeds using CompositeCollection

nice Rudi

Wednesday, March 19, 2008 7:31 PM by sacha

# re: Aggregating Feeds using CompositeCollection

This is the best use of CompositeCollection I've seen to date!  ;-)

Very nice!

Wednesday, March 19, 2008 11:13 PM by Dr. WPF

# re: Aggregating Feeds using CompositeCollection

Tnx guys...

Coming from the people whose great articles I read daily... It means a lot!!!

Regards

Rudi

Thursday, March 20, 2008 5:51 AM by rudi

# Aggregating Feeds using CompositeCollection

Your Story is Submitted - Trackback from DotNetShoutout

Wednesday, November 19, 2008 2:59 PM by DotNetShoutout