Click here to Skip to main content
15,887,485 members
Articles / Programming Languages / Visual Basic

Weather Using VB.NET and Yahoo RSS!

Rate me:
Please Sign up or sign in to vote.
4.05/5 (13 votes)
7 Nov 2008CPOL2 min read 66.1K   4.2K   24  
Weather Using VB.NET and Yahoo RSS!
Imports Microsoft.VisualBasic
Imports System.Xml.Serialization
Public Class YahooWeatherForecast
    Public Enum conditionCode
        tornado = 0
        tropical_storm = 1
        hurricane = 2
        severe_thunderstorms = 3
        thunderstorms = 4
        mixed_rain_and_snow = 5
        mixed_rain_and_sleet = 6
        mixed_snow_and_sleet = 7
        freezing_drizzle = 8
        drizzle = 9
        freezing_rain = 10
        showers = 11
        showers_ = 12
        snow_flurries = 13
        light_snow_showers = 14
        blowing_snow = 15
        snow = 16
        hail = 17
        sleet = 18
        dust = 19
        foggy = 20
        haze = 21
        smoky = 22
        blustery = 23
        windy = 24
        cold = 25
        cloudy = 26
        mostly_cloudy_night = 27
        mostly_cloudy_day = 28
        partly_cloudy_night = 29
        partly_cloudy_day = 30
        clear_night = 31
        sunny = 32
        fair_night = 33
        fair_day = 34
        mixed_rain_and_hail = 35
        hot = 36
        isolated_thunderstorms = 37
        scattered_thunderstorms = 38
        scattered_thunderstorms_ = 39
        scattered_showers = 40
        heavy_snow = 41
        scattered_snow_showers = 42
        heavy_snow_ = 43
        partly_cloudy = 44
        thundershowers = 45
        snow_showers = 46
        isolated_thundershowers = 47
        not_available = 3200
    End Enum

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="p">US zip code or Location ID. </param>
    ''' <param name="U">Units for temperature.  f: Fahrenheit   c: Celsius</param>
    ''' <remarks></remarks>
    Function GetStr(ByVal str As String) As String
        Dim index1 As Integer
        Dim index2 As Integer
        index1 = (str.IndexOf("<![CDATA[")) + Len("<![CDATA[")
        index2 = (str.IndexOf("]]>"))
        ' MsgBox(index1, MsgBoxStyle.Critical, index2)
        Dim str1 As String = str.Substring(index1, index2 - index1)
        'MsgBox(str1)
        Return str1
    End Function
    Sub New(ByVal p As String, ByVal U As String)
        Dim doc As New System.Xml.XmlDocument()
        Dim str As String = "http://xml.weather.yahoo.com/forecastrss?p=" & p & "&u=" & U
        Dim c As rssClass
        'Load data   
        doc.Load(str)
        str = doc.OuterXml
        str = GetStr(str)

        'XmlSerializer could not Serialize XML with this Elements so i just replace them with Null String!
        str = str.Replace("yweather:", "")
        str = str.Replace("geo:", "")
        Dim memoryStream As New IO.MemoryStream()
        Dim d As New IO.StringReader(str)


        Dim xs As New XmlSerializer(GetType(rssClass))

        c = CType(xs.Deserialize(d), rssClass)

        rss = c

    End Sub

    Private _rss As rssClass
    <XmlElement()> _
    Public Property rss() As rssClass
        Get
            Return _rss
        End Get
        Set(ByVal value As rssClass)
            _rss = value
        End Set
    End Property
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) TeraSoft
Jordan Jordan
Nedal Ahmed Odeh
Software development
BS Computer
Deploma IT
Web: http://nedal.faithweb.com

Facebook: http://www.facebook.com/nedal.odeh

Please, do not forget vote
This is a Collaborative Group (No members)


Comments and Discussions