System.Xml.XmlDataDocument.GetElementsByTagName C# (CSharp) Méthode

GetElementsByTagName() public méthode

public GetElementsByTagName ( string name ) : XmlNodeList
name string
Résultat XmlNodeList
        public override XmlNodeList GetElementsByTagName(string name)
        {
            // Retrieving nodes from the returned nodelist may cause foliation which causes new nodes to be created,
            // so the System.Xml iterator will throw if this happens during iteration. To avoid this, foliate everything
            // before iteration, so iteration will not cause foliation (and as a result of this, creation of new nodes).
            XmlNodeList tempNodeList = base.GetElementsByTagName(name);

            int tempint = tempNodeList.Count;
            return tempNodeList;
        }

Usage Example

        public IDictionary<String, String> getWeatherData(String lat, String lon)
        {
            XmlDataDocument doc = new XmlDataDocument();
            IDictionary<String, String> data = new Dictionary<String, String>();
            String url ="http://api.openweathermap.org/data/2.5/forecast/daily?lat=" + lat + "&lon=" + lon + "&cnt=5&mode=xml";
            doc.Load(url);

            XmlNodeList locationList = doc.GetElementsByTagName("location");
            XmlNodeList foreCastList = doc.GetElementsByTagName("time");

            data["City"] = locationList[0].SelectSingleNode("name").InnerText;
            data["Country"] = locationList[0].SelectSingleNode("country").InnerText;

            String temperature,wind,clouds;

            for (int i = 0; i < 5; i++)
            {
                temperature = "Temperature : Morn = " + foreCastList[i].SelectSingleNode("temperature").Attributes["morn"].Value +
                            ",Evening = " + foreCastList[i].SelectSingleNode("temperature").Attributes["eve"].Value + ",Night = " + foreCastList[i].SelectSingleNode("temperature").Attributes["night"].Value;
                wind = "Wind : " + foreCastList[i].SelectSingleNode("windSpeed").Attributes["name"].Value;
                clouds = "Clouds : " + foreCastList[i].SelectSingleNode("clouds").Attributes["value"].Value;

                data[foreCastList[i].Attributes["day"].Value] = temperature + " | " + wind + " | " + clouds;
            }
            return data;
        }
All Usage Examples Of System.Xml.XmlDataDocument::GetElementsByTagName
XmlDataDocument