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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:14:33+00:00 2026-05-31T17:14:33+00:00

I am trying to print out documents in various different orders. Right now I

  • 0

I am trying to print out documents in various different orders. Right now I have a collection of print objects and an XML document where each node has attributes associated with a print object in the collection. I want to sort these objects by sorting the XML document based on these attributes.

Right now I am using a series of collections that i am cycling through and adding the node into a new collection based on the sorting i need done. The problem is 3 or 4 sorts in it gets messy. I am sure there has to be a better way to sort this collection of print objects, using XML or not.

Here are some attributes that my XML has that i am sorting on:

  • # of pages
  • Zip Code listed on document
  • Name of Document

Does anyone have a better idea?

thanks,

EDIT –

my document will look something like

<xml>
<claim key="1" att1="wd" att2="de"/>
<claim key="2" att1="wd" att2="de"/>
<claim key="3" att1="wd" att2="de"/>
<claim key="4" att1="wd" att2="de"/>
</xml>

The key value is associated with a spot in the print object collection. The claim nodes may have more child nodes but i do not think that is relevant at this point. I would just like to be able to sort based on the attributes, there will be at least 3 attributes but more may be added. Also this needs to be versatile so if I need to switch the sorting order it should be somewhat easy to rearrange. Once I have the XML in the correct order I want, then i use a cycle through the XML in order putting the key into a list and then print out the Print objects by the keys in that list.

thanks,

  • 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-31T17:14:34+00:00Added an answer on May 31, 2026 at 5:14 pm

    I tried this example out in LINQPad and it seems to do what you’re asking.

    var root = XDocument.Parse("<xml><claim>...</claim></xml>").Element("xml");
    
    var query = from claim in root.Elements("claim")
                let key = claim.Attributes("key").First().Value
                let att1 = claim.Attributes("att1").First().Value
                let att2 = claim.Attributes("att2").First().Value
                orderby key, att1, att2
                select claim;
    

    It finds the <claim> nodes in your XML, selects the attributes on which you’d like to sort, sorts them, and then returns an IEnumerable<XElement> collection representing the sorted <claim> nodes.

    You can then use the query result to build your Print objects, or you could change the above to have it do it for you:

    var query2 = from claim in root.Elements("claim")
                let key = claim.Attributes("key").First().Value
                let att1 = claim.Attributes("att1").First().Value
                let att2 = claim.Attributes("att2").First().Value
                orderby key, att1, att2
                select new Print {
                            Property1 = key, // do type conversion if needed
                            Property2 = att1,
                            Property3 = att2
                        };
    

    I think it fits the maintainability requirements you mentioned — you just have to change add/remove/change the attribute names in the LINQ query if you need to sort differently.

    EDIT: To get the key into a list of ints, as per your comment below:

    var printKeys = (from claim in query
                    select Integer.Parse(claim.Attributes("key").First().Value)).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 print out the names of each person in the loop.
I'm trying to print to Dot Matrix printers (various models) out of C#, currently
I'm currently trying to print out a document path with SSI in Apache. I've
I'm using Django templating with Google App Engine. I'm trying unsuccessfully to print out
I'm trying to come up with an algorithm that will print out all possible
I'm trying to write a very simple program, I want to print out the
I'm trying to iterate through all nodes, so I can print them out for
I'm trying to figure out how to get text to print sideways in a
I am trying to sort a list of databases and documents in each database
I'm trying to write some code that will print out the dimensions of all

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.