Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-07-2011, 06:35 PM   PM User | #1
wuzhannanan
New Coder

 
Join Date: Jul 2009
Location: Chicago, IL
Posts: 54
Thanks: 5
Thanked 0 Times in 0 Posts
wuzhannanan is an unknown quantity at this point
Format pubDate when displaying RSS feed

Hi all, I am trying to display an RSS feed on my ASP website. Currently, the date is displayed as "Dec 07 2011." I would like to display it as "December 7, 2011." Here is the code I've put together so far:

Code:
<html>
<head>
	<title>RSS Feed Using ASP Classic - For Texas Longhorns Football Schedule from TicketCity.com</title>
	<style>
		*{font-family:verdana;}
		td{vertical-align:top;padding:5px 5px 5px 5px;}
	</style>
</head>
<body>
<%
	' change the RSSURL variable to the exact URL of the RSS Feed you want to pull
	RSSURL = "http://blog.sp.com/feed/?alt=rss"

	Dim objHTTP ' this object is used to call the RSS Feed remotely
	Dim RSSURL,RSSFeed ' these variables hold the URL and Content for the RSS Feed
	Dim xmlRSSFeed ' this variable hold the XML data in a DOM Object
	Dim objItems,objItem, objChild ' these variables are used to temporarily hold data from the various RSS Items
	Dim title,pubdate,description,link '  these are local variables that will hold the data to be displayed
	Dim OutputHTML_1,OutputHTML_2,OutputHTML_3 ' these variables will hold the HTML that was converted from the RSS Feed

	' this code requests the raw RSS/XML and saves the response as a string <RSSFeed>
	Set objHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP")
	objHTTP.open "GET",RSSURL,false
	objHTTP.send
	RSSFeed = objHTTP.responseText

	' this code takes the raw RSSFeed and loads it into an XML Object
	Set xmlRSSFeed = Server.CreateObject("MSXML2.DomDocument.4.0")
	xmlRSSFeed.async = false
	xmlRSSFeed.LoadXml(RSSFeed)

	' this code disposes of the object we called the feed with
	Set objHTTP = Nothing

	' this is where you determine how to display the content from the RSS Feed

	' this code grabs all the "items" in the RSS Feed
	Set objItems = xmlRSSFeed.getElementsByTagName("item")

	' this code disposes of the XML object that contained the entire feed
	Set xmlRSSFeed = Nothing

	' loop over all the items in the RSS Feed
	For x = 0 to objItems.length - 8
		' this code places the content from the various RSS nodes into local variables
		Set objItem = objItems.item(x)
		For Each objChild in objItem.childNodes
			Select Case LCase(objChild.nodeName)
				Case "pubdate"
					  pubDate = objChild.text
				Case "title"
					  title = objChild.text
				Case "link"
					  link = objChild.text
				Case "description"
					  description = objChild.text
			End Select
		Next
		
		ArrayTemp = split(pubDate, " ")
		pubDate2 = ArrayTemp(2) & " " & ArrayTemp(1) & " " & Cint(ArrayTemp(3))
	
		' Here are some various display samples.
		OutputHTML_1 = OutputHTML_1 & pubDate2 & "<br /><a href=""" & link & """>" & title & "</a><br /><br />"
		OutputHTML_2 = OutputHTML_2 & "<a href=""" & link & """>" & title & "</a><br />"
		OutputHTML_3 = OutputHTML_3 & "<a href=""" & link & """>" & title & "</a><hr />"
	Next
%>

<!-- This is the HTML Layout that will render content from the RSS Feed -->
Here is the output, with content provided by the RSS Feed located at:<br /><%=RSSURL%><hr />

<table border="1">
	<tr>
		<td>Ouput Style 1</td>
		<td>Ouput Style 2</td>
		<td>Ouput Style 3</td>
	</tr>
	<tr>
		<td><%=OutputHTML_1%></td>
		<td><%=OutputHTML_2%></td>
		<td><%=OutputHTML_3%></td>
	</tr>
</table>
</body>
</html>
I've been looking for a script online as I'm not skilled enough to create code of my own. Can anyone give me some advice?
wuzhannanan is offline   Reply With Quote
Old 12-07-2011, 10:27 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,200
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
So what does the "raw" pub date look like???

From your code, I would assume it looks something like this:
Code:
Wednesday 07 Dec 2011 and maybe a time here
??

If so, you could do this:
Code:
		temp = Split(pubDate, " ") 
                ' note the comma between (1) and (3) !!
		pubDate2 = ArrayTemp(2) & " " & ArrayTemp(1) & "," & Cint(ArrayTemp(3))
                ' then add this:
                dt = CDate(pubDate2) ' converts it to a VBScript date object
                pubDate2 = Monthname(Month(dt)) & " " & Day(dt) & "," & Year(dt)
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Tags
asp, classic asp, pubdate, rss, rss feed

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:58 AM.


Advertisement
Log in to turn off these ads.