locked
Help with reading XML / RSS feed RRS feed

  • Question

  • I really have not worked much with XML and I would appreciate some help.


    I am trying to read an RSS feed from WeatherBug

    I found some sample code here:

    http://geekswithblogs.net/thibbard/archive/2006/01/13/65764.aspx

    Where they are using System.Data.DataSet to read the XML feed.

    (They are using VBasic I am using VC#)


    Here is a sample of the XML I am trying to read:

    http://api.wxbug.net/getLiveCompactWeatherRSS.aspx?ACode=A5333948364&zipcode=80918&unittype=0&OutputType=1


    In the code example they get the wind speed as follows:

    _wind = DS.Tables("wind-speed").Rows(0).Item("wind-speed_Text")

    How do I know what to specify for each of the index values?  I think I understand how they determined to specify wind-speed but how did they determine how to specify wind-speed_Text?

    I can see the values in my debugger using:

    m_ds.Tables["wind-speed"].Rows[0].ItemArray

    I can see 3 values. "MPH", "3" and 0.

    MPH would be the units.  "3" would be the speed.  Not sure what 0 is.

    And how would I access the value at:

    <aws:api version="2.0"/>

    and

    <aws:WebURL>http://weather.weatherbug.com/CO/Colorado Springs-weather.html?ZCode=Z5546&Units=0&stat=COLED</aws:WebURL>

    ?

    Thanks


    Sunday, April 22, 2012 12:39 AM

Answers

All replies

  • If you want to read an RSS feed from .NET, you can use the classes available in the System.ServiceModel.Syndication namespace: http://msdn.microsoft.com/en-us/library/system.servicemodel.syndication.aspx.

    In particular, that class to start with is SyndacationFeed: http://msdn.microsoft.com/en-us/library/system.servicemodel.syndication.syndicationfeed.aspx.


    Marco Minerva [MCPD]
    Blog: http://blogs.ugidotnet.org/marcom
    Twitter: @marcominerva

    Sunday, April 22, 2012 11:22 AM
  • You can also use WebClient to get the XML feed. Then you can load it in an XDocument and query it through Linq to XML. Here is sample code I made that retrieves the latest news of an RSS feed:

            public static string GetLastNews(string uri)
            {
                return (from xe in XElement.Parse((new WebClient()).DownloadString(uri)).Descendants("item").Elements("title")
                        select xe.Value).FirstOrDefault();
            }


    My blog

    Whether you’re a construction worker, a forum moderator, or just someone that likes helping people. I think these guidelines can be helpful in keeping you helpful when being helpful.

    Sunday, April 22, 2012 12:00 PM
  • You can also use WebClient to get the XML feed. Then you can load it in an XDocument and query it through Linq to XML. Here is sample code I made that retrieves the latest news of an RSS feed:

            public static string GetLastNews(string uri)
            {
                return (from xe in XElement.Parse((new WebClient()).DownloadString(uri)).Descendants("item").Elements("title")
                        select xe.Value).FirstOrDefault();
            }


    My blog

    Whether you’re a construction worker, a forum moderator, or just someone that likes helping people. I think these guidelines can be helpful in keeping you helpful when being helpful.

    Thanks. I was thinking about using XDocument.  But why did the other programmer choose System.Data.DataSet?

    Any chance I can get you an example of how I would access an attribute and a value in my xPage>

    I also saw an example of using selectSingleNode.   Is that a way to go to?

    Sunday, April 22, 2012 1:23 PM
  • XDocument is reasonably new so most examples would use other techniques.  A lot of programmers will use the first hit without thinking too much about future proofing their code.


    Ta Ken

    Monday, April 23, 2012 12:59 AM