reading xml node attribute returns null



I am attempting to get the value of attribute "city" from the node "yweather:location" but it is returning a null value.


enter image description here


This is what I have attempted:



public class Location
{
private String town;

public String Town
{
get { return town; }
}

public void updateLocation(String woeid)
{

String query = String.Format("http://ift.tt/1CCuImR}", woeid);

XmlDocument weatherData = new XmlDocument();
weatherData.Load(query);

XmlNode channel = weatherData.SelectSingleNode("rss").SelectSingleNode("channel");
XmlNamespaceManager man = new XmlNamespaceManager(weatherData.NameTable);
man.AddNamespace("yweather", "http://ift.tt/NpgW1h");

town = channel.SelectSingleNode("yweather:location", man).Attributes["city"].Value;

}

}


Why is this returning null?


No comments:

Post a Comment