0

http://api.met.no/weatherapi/locationforecast/1.9/?lat=49.8197202;lon=18.1673554 XMLで作業しようとしています。各温度要素のすべての値属性を選択したいとしましょう。

私はこれを試しました。

        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);
        }

しかし、私はいつも何も得ません。私は何を間違っていますか?

4

2 に答える 2

0

各属性をループしようとしていますか?

foreach (XmlNode node in nodes)
        {
            //You could grab just the value like below
            Console.WriteLine(node.Attributes["value"].Value);

            //or loop through each attribute
            foreach (XmlAttribute f in node.Attributes)
            {
                 Console.WriteLine(f.Value);
            }
        }
于 2016-12-15T20:01:09.937 に答える