void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { if (e.Error == null) { StringReader stream = new StringReader(e.Result); XmlReader reader = XmlReader.Create(stream); string Day = String.Empty; string Low = String.Empty; string High = String.Empty; string Condition = String.Empty; reader.MoveToContent(); while (reader.Read()) { switch (reader.Name) { case ("day_of_week"): { listBox1.Items.Add(new ListBoxItem() { Content = reader.GetAttribute("data") }); Day = Content.ToString(); } break; case ("low"): { listBox1.Items.Add(new ListBoxItem() { Content = reader.GetAttribute("data") }); Low = Content.ToString(); } break; case ("high"): { listBox1.Items.Add(new ListBoxItem() { Content = reader.GetAttribute("data") }); High = Content.ToString(); } break; case ("condition"): { listBox1.Items.Add(new ListBoxItem() { Content = reader.GetAttribute("data") }); Condition = Content.ToString(); } break; } } reader.Close(); } }
XDocument doc = XDocument.Load("Gweather.xml"); foreach (XElement element in doc.Descendants("forecast_conditions")) { //... }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionvar x from c in doc.Root.Element("weather").Elements() where c.Name "forecast_conditions" select c;
if (x.Any()) { // x n'est pas vide ! }