Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6021313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:41:42+00:00 2026-05-23T03:41:42+00:00

I need some help making a linq query that will select a list of

  • 0

I need some help making a linq query that will select a list of Product objects. Each product object contains a list of ProductItem. The part that I am not sure how to do is how to create the Product.ProductItems list. Can someone give me a hand. Here is the Product, ProductItem, and an example of the xml structure Im playing with.

Here is an example of the direction I was going with this:

XDocument xDocument = XDocument.Load("../Content/index.xml");
            return xDocument.Descendants("item")
                .Select(arg =>
                        new Product
                        {
                            Name = arg.Parent.Attribute("name").Value,
                            ProductItems = new ProductItem{//set properties for PI} // This is where Im stuck.


                        })
                .ToList();
        }

I am trying to sharpen my linq/lambda skills so if you could give me and example that uses the lambda syntax I would appreciate it!

Thanks a ton.

public class Product
{
    public string Name { get; set; }
    public IList<ProductItem> ProductItems { get; set; }

}

public class ProductItem
{
    public string Hwid { get; set; }
    public string Href { get; set; }
    public string Localization { get; set; }
    public DateTime BuildDateTime { get; set; }
    public string IcpBuildVersion { get; set; }
}

}

<products>
<product name="Product1">
  <item hwid="abk9184">
    <href>Product1/abk9184_en-us/abk9184.html</href>
    <localization>en-us</localization>
    <build.start>2011-06-08 22:02 PM</build.start>
    <build.icp>9.0.192.32</build.icp>
  </item>
  <item hwid="abk9185">
    <href>LearningModules/abk9185_en-us/abk9185.html</href>
    <localization>en-us</localization>
    <build.start>2011-06-08 22:03 PM</build.start>
    <build.icp>9.0.192.32</build.icp>
  </item>
</product>
<product name="Product2">
  <item hwid="aa6410">
    <href>Product2/aa6410_en-us/aa6410.html</href>
    <localization>en-us</localization>
    <build.start>2011-06-08 22:04 PM</build.start>
    <build.icp>9.0.192.32</build.icp>
  </item>
  <item hwid="tu6488">
    <href>Product2/tu6488_en-us/tu6488.html</href>
    <localization>en-us</localization>
    <build.start>2011-06-08 22:04 PM</build.start>
    <build.icp>9.0.192.32</build.icp>
  </item>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:41:42+00:00Added an answer on May 23, 2026 at 3:41 am

    You should be going through the Product elements, not descendant items. Then it is easier to collect the items per product.

    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();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good people - Need a little help. I am making a site that will
I have a vbscript that I want to run in the <head> of an
First off, allow me to state that I detest Macs in their entirety. I
I have a set of structured data, that I'm trying to merge together, based
I am trying to dynamically map JSON information into different objects. But I can't
Im making a (small) site in php & mysql. The mysql database consists of
Okay, so not sure if apple.stackexchange is a better place for this, but I
I've been my head against this for most of the day. I don't think
I'm a reasonably intelligent guy and have been involved in a lot of stuff

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.