Reputation: 1030
I am using Global Weather Web Service in my asp.net application http://www.webservicex.net/globalweather.asmx?op=GetWeather.
The code works fine but I want to get only temperature to be displayed on label.
ServiceReference1.GlobalWeatherSoapClient client = new ServiceReference1.GlobalWeatherSoapClient("GlobalWeatherSoap");
string weather = client.GetWeather("Karachi Airport", "Pakistan");
Label1.Text = weather;
Label control is showing complete data provided by service (i.e Date, Time, Country and city name etc)
Upvotes: 0
Views: 1579
Reputation: 1194
You can get it like this also
string weather = client.GetWeather("Karachi Airport", "Pakistan");
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(weather );
XmlNodeList elemlist = xmlDoc.GetElementsByTagName("Temperature");
string temp= elemlist[0].InnerXml;
Upvotes: 2
Reputation: 1444
According to the link you have provided it returns that string in XML form.
So Use it as below:
var doc = XDocument.Parse(weather); //use .Load if you are pulling an xml file.
var location = doc.Root.Element("Location").Value;
var Temperature = doc.Root.Element("Temperature").Value;
Label1.Text = Temperature;
Just Like above you can get another values too e.g. DewPoint, RelativeHumidity etc
var DewPoint= doc.Root.Element("DewPoint").Value;
var RelativeHumidity = doc.Root.Element("RelativeHumidity ").Value;
Upvotes: 2