Friday, 15 August 2014

asp.net - Get a specific number of results from an XmlDocument XPath query -


I am inquiring with a Twitter RSS feed and sending the result to the repeater for display. I would only like to get the first 5 results of the XPath query Is there a way to do this in XPath syntax or do I have to loop on the result XmlNodeList to remove the first 5?

  XmlDocument doc = new XmlDocument (); XmlTextReader Reader = New XmlTextReader (rssPath); Doc.Load (reader); XmlNodeList item = doc.SelectNodes ("/ RSS / Channel / Items"); RptTwitter.ItemDataBound + = New Repeater Item Event Handler (RPTTVwitter_itam.databound); RptTwitter.DataSource = Items; RptTwitter.DataBind (); Try this XPath query instead:  
 

Code> (/ RSS / channel / items) [status () & lt; = 5]

This only returns the first five matching items, because the brackets are important, because without them [position () part item is applied to the position of the element, not its results set in the node.


No comments:

Post a Comment