I'm working on a Silverlight web application that works with XML similar to:
<?xml version="1.0" encoding="UTF-8" ?>
<ProjectList>
<Type>web</Type>
<Project>
<Id>1</Id>
<Name>test web project</Name>
<Description>test web project</Description>
<ScreenshotList>
<Screenshot>
<Path>screen1.jpg</Path>
<Description>This a description of screen 1</Description>
</Screenshot>
<Screenshot>
<Path>screen2.jpg</Path>
<Description>This a description of screen 2</Description>
</Screenshot>
<Thumb>noThumb.jpg</Thumb>
</ScreenshotList>
</Project>
</ProjectList>
I would like to create a new object for each Project element in the XML. I have a class called project which contains fields for id, name, description, thumb and a list for all the screenshots.
My current LINQ code looks like:
var projects = from project in xDoc.Root.Elements("Project")
select new Project(
Int32.Parse(project.Element("Id").Value, CultureInfo.InvariantCulture),
project.Element("Name").Value,
project.Element("Description").Value,
project.Element("ScreenshotList").Element("Thumb").Value
);
Is there anyway for me to easily get the screenshots and add them to the list in the instance of Project within this one query?
EDIT - Adding Project constructorpublic Project(int id, string name, string description, string thumbPath)
{
this.id = id;
this.name = name;
this.description = description;
this.thumbPath = thumbPath;
}