谁能指导我如何在Silverlight(C#)中使用XElement读取XML文件。
谢谢!
最佳答案
这是一些示例代码:
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;
}