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

The Archive Base Latest Questions

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

I have a noob LINQ to XML question. I have xml like so: <pages>

  • 0

I have a noob LINQ to XML question. I have xml like so:

<pages>
    <page Name="Welcome" Control="Welcome" Order="1"></page>
    <page Name="Summary" Control="Summary" Order="10"></page>
</pages>

I need to read in the data and save it to an array ordered by the “Order” attribute. Here’s what I have; the compiler is coughing on the order by clause.

//read in app.xml data into _Pages
XDocument doc = XDocument.Parse("app.xml");
XElement Pages = (XElement)doc.Descendants("pages");

var Pages1 =
  (from page in Pages  //<-- error on orderby clause
  orderby page.order
  select page).ToArray();

I’ve search SO and found several LINQ to XML answers looking like this, but say something about the xml fragment in an object like Pages. But never show it’s type.

Thanks

EDIT:
The error is: Could not find an implementation of the query pattern for source type ‘System.Xml.Linq.XElement’. ‘OrderBy’ not found.

  • 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-12T14:12:38+00:00Added an answer on May 12, 2026 at 2:12 pm

    I’m guessing you want something like this:

    using System.Linq;
    using System.Xml.Linq;
    namespace SampleApp
    {
        class Program
        {
            static void Main(string[] args)
            {
                string xml = @"<pages>   
                    <page Name=""Summary"" Control=""Summary"" Order=""10""></page> 
                    <page Name=""Welcome"" Control=""Welcome"" Order=""1""></page>
                </pages>";
                XDocument doc = XDocument.Parse(xml);
                XElement[] pages = doc
                  .Descendants("page")
                  .OrderBy(x => (int)x.Attribute("Order"))
                  .ToArray();
            }
        }
    }
    

    Does that work for you? This works providing the Order attribute is always an int (I have made an assumption here).

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

Sidebar

Related Questions

Noob question here! I have an array with hashes that looks like this: arr
I've I have a simple noob question, I would like to hide the navigation
Noob Question here. I have created and successfully added an additional Page Layout to
Linq noob here. I have IList<Product> ApplicableProducts and a IList<Product> CurrentProducts. I need to
I am really new to XML and JDOM so I have a noob question,
Noob question. I have an activate handler in a child List , but it
Bit of a noob question but: I have a custom class defined as: public
Applogies for what I have no doubt is a noob question. I display several
I have a noob question =P How can I programatically add a canvas to
I am a Rails noob and have a question. I have a feed aggregator

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.