我試圖用http://api.met.no/weatherapi/locationforecast/1.9/?lat=49.8197202;lon=18.1673554 XML工作。假設我想選擇每個溫度元素的所有值屬性。C#的XmlDocument選擇節點返回空
我想這一點。
const string url = "http://api.met.no/weatherapi/locationforecast/1.9/?lat=49.8197202;lon=18.1673554";
WebClient client = new WebClient();
string x = client.DownloadString(url);
XmlDocument xml = new XmlDocument();
xml.LoadXml(x);
XmlNodeList nodes = xml.SelectNodes("/weatherdata/product/time/location/temperature");
//XmlNodeList nodes = xml.SelectNodes("temperature");
foreach (XmlNode node in nodes)
{
Console.WriteLine(node.Attributes[0].Value);
}
但是我什麼都沒有得到。我究竟做錯了什麼?
所以大概這說明不文檔中存在。也存在使用XDocument – mybirthname
。我必須使用XmlDocument類。我必須爲學校項目和必要的指定做這件事。 – gygabyte