MariamKh
Messages postés5Date d'inscriptionjeudi 23 juin 2011StatutMembreDernière intervention31 janvier 2012
-
14 juil. 2011 à 13:44
BunoCS
Messages postés15475Date d'inscriptionlundi 11 juillet 2005StatutModérateurDernière intervention23 avril 2024
-
15 juil. 2011 à 15:34
Bonjour,
j'ai posé hier une question mais malgré vos propositions j'ai pas réussie à faire fonctionner mon application, j'ai donc essayé une autre méthode mais ça ne réussi pas non plus. Le problème c'est que mon fichier XML est un peu trop complexe , et que je ne voudrais afficher que quelques données :("forecast_conditions"/"day_of_week","low","high","condition").
XML:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO;
using System.Xml;
namespace WeatherDev
{
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
string wk_url = "http://www.google.com/ig/api?weather=hammamet";
Uri url = new Uri(wk_url, UriKind.Absolute);
WebClient wkclient = new WebClient();
wkclient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wkclient_DownloadStringCompleted);
wkclient.DownloadStringAsync(url);
}
void wkclient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
StringReader stream = new StringReader(e.Result);
XmlReader reader = XmlReader.Create(stream);
string jour = String.Empty;
string low = String.Empty;
string high = String.Empty;
string condition = String.Empty;
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name=="forecast_conditions")
{
if(reader.GetAttribute("day_of_week")=="data")
{
jour = reader.GetAttribute("data");
this.textBox1.Text = jour;
}
/* case "low":
{
low = reader.GetAttribute("data");
this.textBox2.Text = low;
case "high":
{
high = reader.GetAttribute("data");
this.textBox3.Text = high;
case "condition" :
{
condition = reader.GetAttribute("data");
this.textBox4.Text = condition;
}
}
}
}
}
}
}
MariamKh
Messages postés5Date d'inscriptionjeudi 23 juin 2011StatutMembreDernière intervention31 janvier 2012 14 juil. 2011 à 13:51
Bonjour,
je m'excuse pour les fautes, j'ai réécrit le code.
J'ai posé hier une question mais malgré vos propositions j'ai pas réussie à faire fonctionner mon application, j'ai donc essayé une autre méthode mais ça ne réussi pas non plus. Le problème c'est que mon fichier XML est un peu trop complexe , et que je ne voudrais afficher que quelques données :("forecast_conditions"/"day_of_week","low","high","condition").
XML:
Code XML :