Hi,
Can anyone please guide me on how to use XElement in Silverlight (C#) to read an XML file.
Thank You!
Hi,
Can anyone please guide me on how to use XElement in Silverlight (C#) to read an XML file.
Thank You!
Here's some example code:
private void Page_Loaded(object sender, RoutedEventArgs e)
{
DataGrid1.ItemsSource = GetStatusReport();
}
public List<Status> GetStatusReport()
{
List<Status> statusReport = new List<Status>();
XElement doc = XElement.Load(@"Data/StatusReport.xml");
statusReport = (from el in doc.Elements()
select GetStatus(el)).ToList();
return statusReport;
}
private Status GetStatus(XElement el)
{
Status s = new Status();
s.Description = el.Attribute("Description").Value;
s.Date = DateTime.Parse(el.Attribute("Date").Value);
return s;
}
Hi there,
you can use the static XElement.Load method to load XML e.g. from a file stream or directly from an XML file packaged into the .XAP.
Here's an example: link text
The MSDN page on XElement might also be helpful (Google: silverlight XElement class).
Cheers, Alex