Articles
AccessDataSource is thickbroken emails in outlook 2007ByRef and ByVal in vbscriptcannot remove movieclipClassic asp crib sheetdecimal places in linux flash playerdouble margins in IE6double spaced IE list itemsextra image padding in html emailsFirefox onsubmit image changeIE7 border style dotted glitchlimit records in accessweather rss feedLast updated: 24/03/2008 16:29:03 GMT
weather rss feed
Recently i decided that i wanted a weather rss feed on my mobile phone (a sony ericsson). The BBC provide a good weather feed so i subscribed to it. It downloaded fine the first time and i was happy. But come day two, when i looked for my updated weather feed i was disappointed to see the previous day's feed still there.I didn't think that the phone was wrong as i had another feed from the BBC and this worked fine. After a bit of digging and comparing the two feeds it became apparent that it was because the GUID was not being changed from day to day in the weather feed. As i was really quite keen to have a working weather feed on my phone i decided i would load the feed on a remote server, change the GUID to be unique then write out the xml. My phone could then download this revised feed, and hopefully i would get an up to date daily weather report.
Additionally there was no Time To Live specified, and the pubdate and last build date were set to (none). I don't know whether these are required for the phone to update the feed but i thought it best to change them as well.
Here is the code (its on an American server hence the session.LCID and the dateadd):
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Xml" %>
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
session.LCID = 2057
Dim xmlID As String
'Thu, 21 Feb 2008 05:29:54 GMT
Dim rightNow as DateTime = dateAdd("h",5,DateTime.Now)
Dim theDate As String
theDate = rightNow.ToString("ddd, d MMM yyyy HH:mm:ss") & " GMT"
xmlID = Request.QueryString("xmlID")
If xmlID = "" Then xmlID = "0008"
Dim myXMLDocument As XmlDocument = New XmlDocument
Try
myXMLDocument.Load("http://feeds.bbc.co.uk/weather/feeds/rss/5day/id/" + xmlID + ".xml")
Catch ex As Exception
myXMLDocument.Load("http://localhost/weather.xml")
End Try
Dim myXMLnodelist As XmlNodeList = myXMLDocument.GetElementsByTagName("pubDate")
myXMLnodelist.Item(0).ParentNode.RemoveChild(myXMLnodelist.Item(0))
'add the ttl to the document
Dim elem As XmlElement = myXMLDocument.CreateElement("ttl")
elem.InnerText = "15"
'Add the node to the document.
myXMLnodelist.Item(0).ParentNode.ParentNode.InsertBefore(elem, myXMLnodelist.Item(0).ParentNode.ParentNode.FirstChild)
For Each x As XmlNode In myXMLnodelist
x.InnerText = theDate
Next
myXMLnodelist = myXMLDocument.GetElementsByTagName("lastBuildDate")
myXMLnodelist.Item(0).InnerText = theDate
myXMLnodelist = myXMLDocument.GetElementsByTagName("guid")
For Each x As XmlNode In myXMLnodelist
x.InnerText = x.InnerText & " " & theDate
Next
Response.ContentType = "text/xml"
Response.Write(myXMLDocument.OuterXml.ToString)
End Sub
</script>
Does it work? Yes, now i have a working weather rss feed on my phone.

