yesterday i did ask about how to extract some data from a complicated xml file , using web service, on the Windows Phone 7 , but unfortuntly i did not get an answer, and i’m still stuck.
This is the c# code i wrote and did not display the data on my application’s screen:
public MainPage()
{
InitializeComponent();
SupportedOrientations = SupportedPageOrientation.Portrait | SupportedPageOrientation.Landscape;
Uri url = new Uri("http://www.google.com/ig/api?weather=paris", UriKind.Absolute);
WebClient client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
client.DownloadStringAsync(url);
}
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
ListBoxItem areaItem = null;
StringReader stream = new StringReader(e.Result);
XmlReader reader = XmlReader.Create(stream);
string day = String.Empty;
string areaName = String.Empty;
string low = String.Empty;
string high = String.Empty;
string condition = String.Empty;
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.Name)
{
case ("day_of_week"):
{
if (true == reader.MoveToFirstAttribute())
{
reader.MoveToContent();
day = reader.ReadElementContentAsString();
day = reader.Value.ToString();
areaItem = new ListBoxItem();
areaItem.Content = day;
listBox1.Items.Add(areaItem);
}
} break;
case ("low"):
{
if (true == reader.MoveToFirstAttribute())
{
reader.MoveToContent();
low = reader.ReadElementContentAsString();
low = reader.Value.ToString();
areaItem = new ListBoxItem();
areaItem.Content = low;
listBox1.Items.Add(areaItem);
}
} break;
case ("high"):
{
if (true == reader.MoveToFirstAttribute())
{
reader.MoveToContent();
high = reader.ReadElementContentAsString();
high = reader.Value.ToString();
areaItem = new ListBoxItem();
areaItem.Content = high;
listBox1.Items.Add(areaItem);
}
} break;
case ("condition"):
{
if (true == reader.MoveToFirstAttribute())
{
reader.MoveToContent();
condition = reader.ReadElementContentAsString();
condition = reader.Value.ToString();
areaItem = new ListBoxItem();
areaItem.Content = condition;
listBox1.Items.Add(areaItem);
}
} break;
}
}
}
}
}
}
}
You are overcomplicating everything, its really simple, use the
and so on
all you do from here on is Bind the Data to your XAML data template
Article Here