getting the first 5 items in my xml datasource

I have the following on my .aspx:
<asp:XmlDataSource ID="xDS" runat="server"></asp:XmlDataSource>

I then have in my code behind:
 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            Dim xmlDoc As New XmlDocument


            xDS.Data = xmlDoc.OuterXml
            xDS.XPath = "rss/channel/item"

            rptNews.DataSource = xDS
        End If
    End Sub

This works fine.

The only problem is that I only want to display the first 5 items.

Is there a simple way of doing this using the xmldatasource?
Who is Participating?
cslimrunConnect With a Mentor Commented:
you could try this:
xDS.XPath = "rss/channel/item[position() <= 5]"


load the xml into a dataset and use a dataview to filter down to just the top 5 rows.
scm0smlAuthor Commented:
this worked nicely:
xDS.XPath = "rss/channel/item[position() <= 4]"
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.