xmlファイルは次の場所にあります:http://api.wunderground.com/api/adaebe40743a9ca6/geolookup/conditions/forecast/q/India/Pilani.xml
今、私はで値をフェッチしたいと思いますtemp_c, relative_humidity, wind_string
。
そのために、WeatherReader.csクラスを次のように作成しました。
using System;
using System.Net;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Xml;
namespace CNGS
{
public class WeatherReader
{ public int Temp;
public string Humidity;
public string Wind;
public string place;
private void PopulateWeatherData()
{
XmlReader reader = XmlReader.Create("http://api.wunderground.com/api/adaebe40743a9ca6/geolookup/conditions/forecast/q/India/Pilani.xml");
reader.MoveToContent();
while (reader.Read())
{
if (reader.LocalName == "temp_c")
{
Temp = Convert.ToInt32(reader.Value);
}
if (reader.LocalName == "relative_humidity")
{
Humidity=reader.Value;
}
if (reader.LocalName == "wind_string")
{
Wind= reader.Value;
}
}
reader.Close();
}
}
}
それは正しいですか、それは必要な値をフェッチしますか?
この情報をSilverlightページに表示したいので。クラスweatherreaderのオブジェクトを次のように作成しようとしました
WeatherReader Weath = new WeatherReader();
しかし、Temp、Windの値などを取得する方法がわかりませんか?何も機能していませんint tmp = Weath.Temp
。
助けてください
天気データを取得し、それをMainPageのSilverlightコントロールで使用して、ライブ天気予報を表示したいと思います。
ありがとう