My xml:
<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>
Country class:
public class Country
{
public String Name { get; set; }
public String NumericCode { get; set; }
public String FileName { get; set; }
}
This is how i create objects from it using LINQ:
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();
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.
Any idea why that would be happening?