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

  • SEARCH
  • Home
  • 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 6037627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:06:07+00:00 2026-05-23T06:06:07+00:00

I am trying to get familiar with using the XDocument API to parse XML

  • 0

I am trying to get familiar with using the XDocument API to parse XML using the lambda syntax.

What I would like to do is create a IEnumerable list of Product based on the following XML structure. I know how to get all of the product nodes but I want to get each of the product nodes name attribute and then select each item node from within the ‘product’ node and parse it for its values.

So I want to take this XML:

<products>
  <product name="Prod1">
    <item hwid="abk9184">
      <href>Prod1/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>Prod1/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="Prod2">
    <item hwid="aa6410">
      <href>Prod2/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>
  </product>
</products>

And from it I would like to get a list of these:

public class Product
{
    public string Name { get; set; }
    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; }
}

So although I have 2 product nodes I would end up with many product instances of each. I’d like to learn how to do this using the XDocument and the lambda syntax. Can someone show me the way?

IEnumerable<Product> products = xDocument.Decendants("product")
                                .Select(e => new Product { Name = e.Name })

But think there would have to be some looping here to get each item from each product.

  • 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-23T06:06:08+00:00Added an answer on May 23, 2026 at 6:06 am
    var products = document.Descendants("item")
        .Select(arg => 
            new Product
            {
                Name = arg.Parent.Attribute("name").Value,
                Hwid = arg.Attribute("hwid").Value,
                Href = arg.Element("href").Value,
                Localization = arg.Element("localization").Value,
                BuildDateTime = DateTime.Parse(arg.Element("build.start").Value),
                IcpBuildVersion = arg.Element("build.icp").Value
            })
        .ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to get familiar with spatial data using sql server 2008. I use
I'm trying to get familiar with the whole keyboard event detection thing. Here's my
I'm trying to get started with USSD . I'm familiar with other forms of
I'm trying get values from a GridView using the following code: foreach (GridViewRow row
Trying to get my css / C# functions to look like this: body {
Trying to get parameters from a PUT request using HttpServlet#doPut: public void doPut(HttpServletRequest request,
I'm trying to get familiar with CI and I have run into a problem
I'm trying to pull some data into my CakePHP site using a REST API.
I am trying to connect to Webtrend's API using PHP but haven't been able
I'm simply trying to get data from two sql server db tables using ado.net

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.