i’m trying to create an application with Windows Phone 7, which displays data from a specific URI, but it won’t work. I’m stack,help me please.
This is my XML :
<?xml version="1.0" encoding="utf-8" ?>
<weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0">
<forecast_conditions>
<day_of_week data="lun."/>
<low data="28"/>
<high data="38"/>
<icon data="/ig/images/weather/mostly_sunny.gif"/>
<condition data="Partiellement ensoleillé"/>
</forecast_conditions>
<forecast_conditions>
<day_of_week data="mar."/>
<low data="27"/>
<high data="39"/>
<icon data="/ig/images/weather/sunny.gif"/>
<condition data="Temps clair"/>
</forecast_conditions>
<forecast_conditions>
<day_of_week data="mer."/>
<low data="25"/>
<high data="38"/>
<icon data="/ig/images/weather/mostly_sunny.gif"/>
<condition data="Ensoleillé dans l'ensemble"/>
</forecast_conditions>
<forecast_conditions>
<day_of_week data="jeu."/>
<low data="24"/>
<high data="33"/>
<icon data="/ig/images/weather/mostly_sunny.gif"/>
<condition data="Ensoleillé dans l'ensemble"/>
</forecast_conditions>
</weather>
This is my c# code:
namespace WEATHER2
{
public partial class MainPage : PhoneApplicationPage
{
// Constructeur
public MainPage()
{
InitializeComponent();
XDocument doc = XDocument.Load("Gweather.xml");
var x= from c in doc.Descendants("forecast_conditions")
select new Weather_Element()
{
Day = (string)c.Attribute("day_of_week").Value,
Low = (string)c.Attribute("low").Value,
High = (string)c.Attribute("high").Value,
Condition = (string)c.Attribute("condition").Value
};
listBox1.ItemsSource = x;
}
public class Weather_Element
{
string day;
string low;
string high;
string condition;
public string Day
{
get { return day; }
set { day = value; }
}
public string Low
{
get { return low; }
set { low = value; }
}
public string High
{
get { return high; }
set { high = value; }
}
public string Condition
{
get { return condition; }
set { condition = value; }
}
}
}
}
You are trying to get attribute values from the an element without attributes.
The element
cof typeforecast_conditionshas an elementday_of_week. Then this element has an attributedata.