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!!!