I'm trying to load country names and their cities from an XML file in silver-light.
I want the cities to be loaded to a ListPicker according to the selected country.
This is a part of my XML file:
<Times>
<country name="USA">
<city name="Aaronsburg -- PA">
<state>PA</state>
<latitude>408739</latitude>
<longitude>-773815</longitude>
<timezone>-500</timezone>
<daylight>1</daylight>
</city>
<city name="Abbeville -- AL">
<state>AL</state>
<latitude>316077</latitude>
<longitude>-853051</longitude>
<timezone>-600</timezone>
<daylight>1</daylight>
</city>
<city name="Abbeville -- GA">
<state>GA</state>
<latitude>319710</latitude>
<longitude>-833016</longitude>
<timezone>-500</timezone>
<daylight>1</daylight>
</city>
<city name="Abbot -- ME">
<state>ME</state>
<latitude>453219</latitude>
<longitude>-695342</longitude>
<timezone>-500</timezone>
<daylight>1</daylight>
</city>
........
........
and this the code I wrote:
private void LoadButton_Click(object sender, RoutedEventArgs e)
{
XDocument doc = XDocument.Load("Athan.xml");
var definitions = doc.Document.Descendants(XName.Get("country"));
foreach (var definition in definitions)
{
if (definition.Attribute(XName.Get("name")).Value == CountryListPicker.SelectedItem.ToString())
{
var cities = definition.Document.Descendants(XName.Get("city"));
foreach (var city in cities)
{
CityListPicker.Items.Add(city.Attribute(XName.Get("name")).Value.ToString());
}
return;
}
}
}
cities are loaded after a long time, or not loaded! is something wrong with my code?