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
            myXMLDocument.Load("" + xmlID + ".xml")
        Catch ex As Exception
        End Try
        Dim myXMLnodelist As XmlNodeList = myXMLDocument.GetElementsByTagName("pubDate")
        '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
        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
        Response.ContentType = "text/xml"
    End Sub

Does it work? Yes, now i have a working weather rss feed on my phone.

Post a comment