score:17

Accepted answer

You should be going through the Product descendants, not items. That way you are reading off of the Product elements. Then it is easier to get the associated items.

var doc = XDocument.Load("../Content/index.xml");
var products = doc.Elements("product")
    .Select(p =>
        new Product
        {
            Name = (string)p.Attribute("name"),
            ProductItems = p.Elements("item")
                .Select(i =>
                    new ProductItem
                    {
                        //set properties for PI
                        Hwid = (string)i.Attribute("hwid"),
                        Href = (string)i.Element("href"),
                        Localization = (string)i.Element("localization"),
                        // etc.
                    })
                .ToList()
        })
    .ToList();

Related Articles