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 6695949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:17:01+00:00 2026-05-26T06:17:01+00:00

I am creating a List of structs using linq to xml. The linq path

  • 0

I am creating a List of structs using linq to xml.

The linq path does not find the concept elements. I have tried various formulations of this and before I give up and use xpath I am hoping someone can show me the linq way. thanks

Here is the xml

<response xmlns="http://www.domain.com/api">
  <about>
    <requestId>E9B73CA1F16A670C966BE2BABD3B2B22</requestId>
    <docId>09E167D994E00B0F511781C40B85AEC3</docId>
    <systemType>concept</systemType>
    <configId>odp_2007_l1_1.7k</configId>
    <contentType>text/plain</contentType>
    <contentDigest>09E167D994E00B0F511781C40B85AEC3</contentDigest>
    <requestDate>2011-10-18T09:51:28+00:00</requestDate>
    <systemVersion>2.1</systemVersion>
  </about>
  <conceptExtractor>
    <conceptExtractorResponse>
      <concepts>
        <concept weight="0.010466908" label="hell"/>
      </concepts>
    </conceptExtractorResponse>
  </conceptExtractor>
</response>

here is what I have

public struct conceptweight
{
    public string concept { get; set; }
    public string weight { get; set; }
}

List<conceptweight> list = (from c
  in d.Descendants("response")
      .Descendants("conceptExtractor")
      .Descendants("conceptExtractorResponse")
      .Descendants("concepts")
  select new conceptweight()
         {
           concept = c.Attribute("label").Value,
           weight = c.Attribute("weight").Value
         }).ToList();
  • 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-26T06:17:01+00:00Added an answer on May 26, 2026 at 6:17 am

    You’ve forgotten the namespace, which is defaulted in the root element. Try this:

    // Note: names changed to follow conventions, and now a class
    // rather than a struct. Mutable structs are evil.
    public class ConceptWeight
    {
        public string Concept { get; set; }
        // Type changed to reflect the natural data type
        public double Weight { get; set; }
    }
    
    XNamespace ns = "http://www.domain.com/api";
    
    // No need to traverse the path all the way, unless there are other "concepts"
    // elements you want to ignore. Note the use of ns here.
    var list = d.Descendants(ns + "concepts")
                .Select(c => new ConceptWeight
                        {
                            Concept = (string) c.Attribute("label"),
                            Weight = (double) c.Attribute("weight"),
                        })
                .ToList();
    

    I haven’t used a query expression here as it wasn’t adding any value – you were only doing from x in y select z, which is more simply expressed via the Select extension method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why does this attempt at creating a list of curried functions not work? def
I have an ARM project that I'm building with make. I'm creating the list
I have been having problems with creating a download list of files for a
javax.servlet.ServletException: Error creating bean with name 'userService' defined in class path resource [applicationContext.xml]: Cannot
I have created a type list. I then create a class using a template
Please guide whats wrong with the following code that its not creating proper list
I have a following sturcture for creating linked list, how can I free the
I'm creating a list of pictures using a ListView and the photos are of
I'm creating a Linked List program and I currently have this method to insert
Im creating a list of Twitter results in PHP, im already using PHP to

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.