Reputation: 3527
I'm trying to import the last 5 posts from a Wordpress RSS feed and show them on my site.
I was using this, but it grabs the whole feed.
<asp:DataList ID="dataNews" runat="server" DataSourceID="xmlSource" >
<ItemTemplate>
<a href="<%# XPath("link") %>"><%# XPath("title") %></a>
</ItemTemplate>
</asp:DataList>
<asp:XmlDataSource ID="xmlSource" runat="server" DataFile="http://myblog.com/feed" XPath="rss/channel/item" EnableCaching="true" />
How can I accomplish this?
Upvotes: 0
Views: 310
Reputation: 613
You can use XPath expressions to help you with this as documented here: Get a specific number of results from an XmlDocument XPath query. The following should work.
<asp:XmlDataSource ID="xmlSource" runat="server" DataFile="http://myblog.com/feed" XPath="rss/channel/item[position()<6]" EnableCaching="true" />
Upvotes: 2