locked
Top 5 RSS articles? RRS feed

  • Question

  • User953575223 posted

    I'm pulling some content (titles/links) from an RSS feed on a Medical News site.  I'd like to only display the top 5 articles; but, I can't figure out how to do it.

     I'm using ASP.NET with VB.

     Here's my DataList:

    <asp:DataList Id="DataList1" runat="server" >

    <ItemTemplate>

    <dd><a href="<%# DirectCast(Container.DataItem, XmlElement).SelectSingleNode("link").InnerText%>" target="_blank"><asp:Label Id="LinkLabel" Runat="Server" CssClass="relatedLinks" Text='<%# DirectCast(Container.DataItem, XmlElement).SelectSingleNode("title").InnerText%>' /></a></dd>

    </ItemTemplate>

    </asp:DataList>

    Here's my code from the code behind:

    Dim readerXML As New XmlTextReader("http://www.medicalnewstoday.com/rss/healthinsurance.xml")Dim document As New XmlDocument()

    document.Load(readerXML)

    DataList1.DataSource = document.SelectNodes(
    "//item")

    DataList1.DataBind()

    Thanks!

    Jennifer

    Tuesday, July 17, 2007 9:56 PM

Answers

  • User223594850 posted

    DataList1.DataSource = document.SelectNodes("//item")

    Hi Jennifer,

    I'm not near my VS but see if this works...

    DataList1.DataSource = document.SelectNodes("//item[position() &lt; 6]")
     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 17, 2007 11:42 PM
  • User-1977747231 posted

    That gives an invalid token error:

     '//item[position() &lt; 6]' has an invalid token.

    Hi

    you need to replace &lt; with < i.e. //item[position() < 6]

    Thanks,

    Kiran

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 18, 2007 10:34 AM

All replies

  • User223594850 posted

    DataList1.DataSource = document.SelectNodes("//item")

    Hi Jennifer,

    I'm not near my VS but see if this works...

    DataList1.DataSource = document.SelectNodes("//item[position() &lt; 6]")
     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 17, 2007 11:42 PM
  • User953575223 posted

    That gives an invalid token error:

     '//item[position() &lt; 6]' has an invalid token.

    Wednesday, July 18, 2007 9:53 AM
  • User-1977747231 posted

    That gives an invalid token error:

     '//item[position() &lt; 6]' has an invalid token.

    Hi

    you need to replace &lt; with < i.e. //item[position() < 6]

    Thanks,

    Kiran

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 18, 2007 10:34 AM
  • User223594850 posted

    you need to replace &lt; with < i.e. //item[position() < 6]

    Thanks Kiran, for pointing that out. [:)]

    (I copied that XPath fragment straight from my XSLT file forgetting to replace the "less than" escape sequence...  [:$])

    Wednesday, July 18, 2007 11:01 AM
  • User953575223 posted

    Sweet!  Works great!  Thanks for your help.

     

    Jennifer

    Wednesday, July 18, 2007 11:09 AM