I'm trying to load xml data in to my ListView control, but not working correctly.
The XML content is:
<?xml version="1.0" encoding="utf-8"?>
<Employees>
<Employee ID="1">
<Name>Numeri</Name>
</Employee>
<Employee ID="5">
<Name>husu</Name>
</Employee>
<Employee ID="6">
<Name>sebri</Name>
</Employee>
</Employees>
This is what I have tried to load the data:
private void btn_load_Click(object sender, EventArgs e)
{
XDocument doc = XDocument.Load(Application.StartupPath + "/Employees.xml");
foreach (var dm in doc.Descendants("Employee"))
{
ListViewItem item = new ListViewItem(new string[]
{
dm.XAttribute("ID").Value,
dm.XElement("Name").Value
});
listView1.Items.Add(item);
}
It is preferable if the help is provided using XML-Linq.
Thanks in Advance.