Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Reading attributes from RSS feed

Posted on 2008-10-06
5
Medium Priority
?
1,398 Views
Last Modified: 2013-11-18
I'm trying to consume this RSS feed below. How do I get the min, max, etc attributes from the w:forecast node using the SyndicationFeed or some other method?

http://rss.weather.com.au/sa/parafield

I did plan on using the class provided here to keep the code succinct.
http://www.clariusconsulting.net/blogs/kzu/archive/2007/11/22/ForgetaboutwritingAtomorRSSXMLhandlingcodeeveragain.aspx

MSDN reference to SyndicationFeed
http://msdn.microsoft.com/en-us/library/system.servicemodel.syndication.syndicationfeed.aspx
WebClient client = new WebClient();
client.Proxy = new WebProxy(proxyAddress, true);
 
Stream strm = client.OpenRead("http://rss.weather.com.au/sa/parafield");
XmlReader reader = XmlReader.Create(strm);
 
SyndicationFeedFormatter formatter = SyndicationFormatterFactory.CreateFeedFormatter(reader);
formatter.ReadFrom(reader);
SyndicationFeed feed = formatter.Feed;
 
Collection<string> timeToLive = feed.ElementExtensions.ReadElementExtensions<string>("ttl", "");
double ttl = 30;
if (timeToLive.Count > 0)
    ttl = Double.Parse(timeToLive[0]);

Open in new window

0
Comment
Question by:brene
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 13

Expert Comment

by:SameerJagdale
ID: 22657834
are you using .net 3.5?
0
 
LVL 4

Author Comment

by:brene
ID: 22664926
Yes, that is why I want to take advantage of the SyndicationFeed class but I'll use any method that works.
0
 
LVL 13

Expert Comment

by:SameerJagdale
ID: 22666401
0
 
LVL 4

Author Comment

by:brene
ID: 22666763
That link shows how to create a feed. I'm trying to get the data from an existing feed so that doesn't help.

What I want is the information contained in the w:forecast node eg.
<w:forecast day="Thursday" description="Early Fog Followed by Sun. Mild." min="8" max="21" icon="12" iconUri="http://www.weather.com.au/images/icons/12.gif" iconAlt="Early Fog Followed by Sun"/>
0
 
LVL 4

Accepted Solution

by:
brene earned 0 total points
ID: 22684156
Worked it out myself.
var items = from i in feed.Items
			select new
			{
				Title = i.Title.Text,
				Link = i.Links[0].Uri.ToString(),
				Ext = i.ElementExtensions
			};
foreach (var item in items)
{
	currWeather.Title = item.Title;
	currWeather.Link = item.Link;
	foreach (SyndicationElementExtension extension in item.Ext)
	{
		if (extension.OuterName == "current")
		{
			XmlReader xReader = extension.GetReader();
			if (xReader.HasAttributes)
			{
				currWeather.Temperature = Double.Parse(xReader["temperature"]);
				currWeather.DewPoint = Double.Parse(xReader["dewPoint"]);
				currWeather.Humidity = Double.Parse(xReader["humidity"]);
				currWeather.WindSpeed = Double.Parse(xReader["windSpeed"]);
				currWeather.WindGusts = Double.Parse(xReader["windGusts"]);
				currWeather.WindDirection = xReader["windDirection"];
				currWeather.Pressure = Double.Parse(xReader["pressure"]);
				currWeather.Rain = Double.Parse(xReader["rain"]);
			}
		}
	}
}

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question