我试图用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