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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:17:38+00:00 2026-05-31T14:17:38+00:00

I am trying to get 4 List deep List collection, List<List<List<List<int>>>> . From my

  • 0

I am trying to get 4 List deep List collection, List<List<List<List<int>>>>. From my Xml which looks like

<root> 
    <Claim key="1" carrier="carA" zip="34343" pages="1"/>
    <Claim key="2" carrier="carA" zip="34343" pages="2"/>
    <Claim key="3" carrier="carB" zip="10505" pages="2"/>
    <Claim key="4" carrier="carB" zip="10505" pages="4"/> 
    <Claim key="5" carrier="carB" zip="10505" pages="4"/>
</root>

the structure of the output should look like

-all
   -1
       -34343
           -carA
                   -1

   -2
       -34343
           -carA
                   -2

       -10505
               -carB
                   -3
   -4
       -10505
           -carB
                    -4
                    -5

the goal is to sort my XML based on the node attributes first by number of pages, then by zip, then by carrier. I will then need to cycle through the result list and process each claim in the particular order. I am having trouble getting the syntax right for 3 nested groups. I have accomplished getting 2 nested groups can anyone help me get the third.

here is my code so far.

var query = from claim in root.Elements("Claim")
                        group claim by claim.Attributes("Pages").First().Value into pageGroups
                        from zipGroups in
                            (from claim in pageGroups
                             group claim by int.Parse(claim.Attributes("CarrierZip").First().Value))
                        group zipGroups by pageGroups.Key;
  • 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-31T14:17:39+00:00Added an answer on May 31, 2026 at 2:17 pm

    If nothing else I believe this code answers your question. Having to handle four nested lists is pretty complex and if you can refactor your solution into something simpler you will probably find that your code will be easier to maintain.

    var xml = @"<root>  
      <Claim key=""1"" carrier=""carA"" zip=""34343"" pages=""1""/> 
      <Claim key=""2"" carrier=""carA"" zip=""34343"" pages=""2""/> 
      <Claim key=""3"" carrier=""carB"" zip=""10505"" pages=""2""/> 
      <Claim key=""4"" carrier=""carB"" zip=""10505"" pages=""4""/>  
      <Claim key=""5"" carrier=""carB"" zip=""10505"" pages=""4""/>
    </root>";
    
    var xElement = XElement.Parse(xml);
    
    var claims = xElement
      .Elements("Claim")
      .Select(
        x => new {
          Key = (Int32) x.Attribute("key"),
          Carrier = (String) x.Attribute("carrier"),
          Zip = (Int32) x.Attribute("zip"),
          Pages = (Int32) x.Attribute("pages")
        }
      );
    
    var lists = claims
      .OrderBy(claim => claim.Pages)
      .GroupBy(claim => claim.Pages)
      .Select(pagesGroup => pagesGroup
        .OrderBy(claim => claim.Zip)
        .GroupBy(claim => claim.Zip)
        .Select(zipGroup => zipGroup
          .OrderBy(claim => claim.Carrier)
          .GroupBy(claim => claim.Carrier)
          .Select(carrierGroup => carrierGroup
            .OrderBy(claim => claim.Key)
            .Select(claim => claim.Key)
            .ToList()
          )
          .ToList()
        )
        .ToList()
      )
      .ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get list of numbers from: numbers= 1,2 to: '1','2' I
I am trying to get a list of Files in a Folder from Google
I am trying to get a list of hrefs from a list of ten
I've trying to get list of updated/added/deleted files from SVN by svnlook using: /usr/bin/svnlook
Im trying to get a list of posts from WordPress for the last 7,30
I'm trying to get a list of unanswered questions from the feed , but
I'm trying to get a list of unique values from the 'type' field from
I am trying to get list of recent posts from a blog filtered by
Trying to get a list of drives from a server side application using a
I'm trying to get a list of all the Hungarian city names from google

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.