ASP RSS Parser, Feed Reader

This weekend, I’ve been glued to my laptop, searching the net for web-based RSS feed readers. The reason is that I wanted to write an ASP RSS feed reader that would display the feed so that the content could be automatically scraped into an HTML email. So, for folks who want to reserve a portion of their email newsletter for their Blog or Publication articles, it could be easily incorporated.
Since JavaScript doesn’t actually display the content until the client loads and executes the script, the plethora of JavaScript RSS browsers wasn’t useful. I needed a server-side RSS feed reader.
To parse an XML feed in ASP, you can use the MSXML library that is available in ASP. Here’s a basic example of how to parse an XML feed using ASP:
<%
' Create an instance of the MSXML DOMDocument object
Set xmlDoc = Server.CreateObject("Msxml2.DOMDocument.6.0")
' Load the XML feed from a URL
xmlDoc.async = False
xmlDoc.load("http://example.com/feed.xml")
' Check if the XML is loaded successfully
If xmlDoc.parseError.errorCode <> 0 Then
Response.Write "Error loading XML: " & xmlDoc.parseError.reason
Else
' Navigate through the XML structure and retrieve data
Set items = xmlDoc.selectNodes("//item") ' Change "item" to the appropriate XML element name in your feed
' Loop through the items
For Each item In items
' Access elements within each item
title = item.selectSingleNode("title").text
link = item.selectSingleNode("link").text
description = item.selectSingleNode("description").text
' Perform your sales and marketing operations with the retrieved data
' For example, you can insert this data into a database or display it on a webpage.
Next
End If
' Clean up the XML document
Set xmlDoc = Nothing
%>
In this code, we first create an instance of the Msxml2.DOMDocument.6.0
object to work with XML. We then load the XML feed from a URL and check if the loading was successful. If there are no errors, we use XPath to navigate through the XML structure and retrieve data from the elements you specify. Finally, you can perform your sales and marketing operations with the retrieved data.
You can modify the output to provide an excerpt with a specific number of words and then add “…” to indicate that the text continues. Here’s an example of how you can do that in your ASP code:
<%
' Create an instance of the MSXML DOMDocument object
Set xmlDoc = Server.CreateObject("Msxml2.DOMDocument.6.0")
' Load the XML feed from a URL
xmlDoc.async = False
xmlDoc.load("http://example.com/feed.xml")
' Check if the XML is loaded successfully
If xmlDoc.parseError.errorCode <> 0 Then
Response.Write "Error loading XML: " & xmlDoc.parseError.reason
Else
' Navigate through the XML structure and retrieve data
Set items = xmlDoc.selectNodes("//item") ' Change "item" to the appropriate XML element name in your feed
' Loop through the items
For Each item In items
' Access elements within each item
title = item.selectSingleNode("title").text
link = item.selectSingleNode("link").text
description = item.selectSingleNode("description").text
' Modify the description to include an excerpt with a specific number of words
excerptLength = 30 ' Change this number to your desired word count
descriptionArray = Split(description, " ")
If UBound(descriptionArray) > excerptLength Then
excerpt = Join(LBound(descriptionArray, excerptLength), " ") & "..."
Else
excerpt = description
End If
' Perform your sales and marketing operations with the excerpt
' For example, you can insert this data into a database or display it on a webpage.
Next
End If
' Clean up the XML document
Set xmlDoc = Nothing
%>
In this code, we added a section that modifies the description
to create an excerpt with a specific number of words (30 in this example) and adds “…” if the description is longer. You can adjust the excerptLength
variable to control the number of words in the excerpt.
This modification will provide you with a truncated description as an excerpt for your sales and marketing operations.
Please replace http://example.com/feed.xml
with the URL of the XML feed you want to parse and adjust the element names and data handling according to your specific XML structure and requirements.