I have an XML structure such as:
[...] <Fruits> <Fruit> <Specification>id_1001_0</Specification> <Weight>23</Weight> </Fruit> </Fruits> <FruitSpecification id="id_1001_0"> <Type>Apple</Type> </FruitSpecification> [...]
I want to use Linq for XML to read this in (non-anonymous) objects. Let's say I have the following code:
var fruits = from xele in xDoc.Root.Element("Fruits").Elements("Fruit") select new Fruit() { Weight = xele.Element("Weight").Value }
How can I expand a query to join the correct FruitSpecification tag? The goal is to write this:
var fruits = from xele in xDoc.Root.Element("Fruits").Elements("Fruit") //some join? select new Fruit() { Weight = xele.Element("Weight").Value, Type = xjoinedelement.Element("Type").Value }
Hope this is understandable, I made this βfruitβ sample, my actual XML is much more complicated ...
source share