I've got an XML file that I want to turn in to a list of POCO objects.
I have the following working code to read the XML and create objects from it. I just want to check this is a good way to do this and I'm not missing any tricks. In particular with regards to the nested Linq query.
XDocument xmlDoc = XDocument.Load(path);
var q = from file in xmlDoc.Descendants("File")
select new ImportDefinition()
{
Name = file.Attribute("Name").Value,
TypeName = file.Attribute("TypeName").Value,
ColumnMappings =
(
from map in file.Descendants("ColumnMap")
select new ColumnMap()
{
DatabaseColumn = new Column()
{
Name = map.Element("DatabaseColumn").Attribute("Name").Value
}
}
).ToList<ColumnMap>()
};
List<ImportDefinition> def = q.ToList<ImportDefinition>();
Thanks