LINQ to XML adds null item to object list

custa

New Member
My xml:\[code\] <Configuration> <LaunchDebugger>false</LaunchDebugger> <RequestFolder>./Request</RequestFolder> <ResponseFolder>./Response</ResponseFolder> <Countries> <Country NumericCode="1FH" FileName="file1.xml">1</Country> <Country NumericCode="20H" FileName="file2.xml">2</Country> <Country NumericCode="" FileName="file3.xml">3</Country> </Countries> </Configuration>\[/code\]Country class:\[code\]public class Country{ public String Name { get; set; } public String NumericCode { get; set; } public String FileName { get; set; }}\[/code\]This is how i create objects from it using LINQ:\[code\] CountryList = (from filter in Configuration.Descendants("Countries").Descendants("Country") select new Country() { Name = (string)filter.Value, NumericCode = (string)filter.Attribute("NumericCode"), FileName = (string)filter.Attribute("FileName") }).ToList();\[/code\]Parsing xml works, i get all 3 countries in my list, but i also get one extra null object as the last item of the list.
mLZW1.png
Any idea why that would be happening?
 
Back
Top