Get a specific number of results from an XmlDocument XPath query

后端 未结 2 1375
离开以前
离开以前 2021-01-13 09:21

I\'m querying a Twitter RSS feed and supplying the results into a Repeater for display. I\'d like to only get the first 5 results of the XPath query. Is there a way to do th

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-13 10:02

    Try this XPath query instead:

    (/rss/channel/item)[position() <= 5]
    

    It returns only the first five matching items. The parentheses are important, as without them the [position() <= 5] part applies to the item element's position in its parent rather than its position in the result node set.

提交回复
热议问题