Scenario:
- Grid view gets populated in WPF window.
- Having a static list in code behind.(which i want to get from a xml file).
Trying to move the static list into an xml file.For that i created a ml file in the following format
<customers>
<customer Name="abc"/>
<customer Name="def"/>
</customers>
CodeBehind:
Xdocument doc=Xdocument.load("customers.xml");
var customerList = (from e in doc.Descendants("Cusomters")
select new
{
CustomerName = e.Attribute("Name").Value
}).ToList();
I am unable to get the customer names from the xml file to the customerList.I would appreciate if someone can help me to move forward.
"Cusomters"is spelled incorrectly, should be"Customers".Obviously this is not the code your are using since it doesn’t even compile. It should be this:
You really should mention the fact that it won’t compile. That, or you copied it in by hand incorrectly, which doesn’t help us help you either.
The logical problem here is that you are asking for all
Customerstags, note thesat the end. You really want to look forCustomertags, which have anameattribute.Customer*s*is simply the top level group.