Entry tags:
Anyone here know ASP/VBscript?
I'm trying to convert an ASP RSS parsing script from reading *every* item in an RSS feed to just reading the 3 most recent items. The original script uses a FOR EACH loop that I'm just not quite figuring out how to change over to a regular loop that I can go through three times.
I did find a version of this online that just breaks it after three iterations, but there's got to be a better way than that. Right?
Is it possible to just set objXML.Load to load the first three items? (Hmm... must invesitgate that...)
I did find a version of this online that just breaks it after three iterations, but there's got to be a better way than that. Right?
Is it possible to just set objXML.Load to load the first three items? (Hmm... must invesitgate that...)
objXML.Load(rssFile)
If (objXML.parseError.errorCode = 0) Then
Set objRoot = objXML.documentElement
If IsObject(objRoot) = False Then
response.Write "No Root Found in Rss File"
End If
Set objItems = objRoot.getElementsByTagName("item")
If IsObject(objItems) = True Then
Dim objItem
For Each objItem in objItems
strTitle = objItem.selectSingleNode("title").Text
On Error Resume Next
strDesc = objItem.selectSingleNode("description").Text
On Error Resume Next
strLink = objItem.selectSingleNode("link").Text
On Error Resume Next
strDate = objItem.selectSingleNode("pubDate").Text
On Error Resume Next
response.Write [formatting and items]
Next

no subject
Set RSSItems = xmldoma.getElementsByTagName("item") For X = 0 To 3 Set RSSItem = RSSItems.Item(X) ... Nextno subject
no subject
no subject
EDIT:
I take that back...*codes*EDIT: No, I take it back. Even if you use XPath to pull out the individual nodes, you've still got to load each node into memory. The best alternative I could come up with is this, which might save a bit of memory since it only declares those objects in the scope of the loop:
For X = 0 To 2 Set RSSItem = xmldoma.getElementsByTagName("item")(X) ... NextEDIT: Okay, seriously, the last time. XPath does work. Here:
Set RSSItems = xmldoma.selectNodes("/rss/channel/item[position()<4]") For X = 0 To RSSLen Set RSSItem = RSSItems.Item(X) ... Next