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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:44:55+00:00 2026-05-17T16:44:55+00:00

<?xml version=1.0 encoding=utf-8?> <Customers> <Customer Id=1> <Name>rtertr</Name> <DOB>2010-12-12T00:00:00</DOB> <EMail>werer@test.com</EMail> </Customer> <Customer Id=2> <Name>west</Name> <DOB>0001-01-01T00:00:00</DOB>

  • 0
<?xml version="1.0" encoding="utf-8"?>
<Customers>
   <Customer Id="1">
    <Name>rtertr</Name>
    <DOB>2010-12-12T00:00:00</DOB>
    <EMail>werer@test.com</EMail>
  </Customer>
  <Customer Id="2">
    <Name>west</Name>
    <DOB>0001-01-01T00:00:00</DOB>
    <EMail>west@test.com</EMail>
   </Customer> 
  <Customer Id="3">
    <Name>west</Name>
    <DOB>0001-01-01T00:00:00</DOB>
    <EMail>west@test.com</EMail>
   </Customer> 
</Customers>

How to find Min and Max CustomerId from the above sample XML using LinQ to XML? For example for the above sample, Min should be 1 and Max should be 3

  • 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-17T16:44:55+00:00Added an answer on May 17, 2026 at 4:44 pm

    You can use the Min and Max extension methods:

    var doc = XDocument.Parse("<Customers>...</Customers>");
    
    var minId = doc.Root.Elements().Min(e => (int)e.Attribute("Id"));
    var maxId = doc.Root.Elements().Max(e => (int)e.Attribute("Id"));
    

    or the Aggregate extension method (iterating the XML document only once):

    var doc = XDocument.Parse("<Customers>...</Customers>");
    
    var result = doc.Root
                    .Elements()
                    .Select(e => (int)e.Attribute("Id"))
                    .Aggregate(
                        Tuple.Create(int.MinValue, int.MaxValue),
                        (t, x) => Tuple.Create(Math.Max(t.Item1, x),
                                               Math.Min(t.Item2, x)));
    
    var maxId = result.Item1;
    var minId = result.Item2;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<?xml version=1.0 encoding=UTF-8?> <form:Documents xmlns:form=http://www.abbyy.com/FlexiCapture/Schemas/Export/FormData.xsd xmlns:addData=http://www.abbyy.com/FlexiCapture/Schemas/Export/AdditionalFormData.xsd> <_Document_Definition_1:_Document_Definition_1 addData:ImagePath=C:\POC\Export\Test.pdf xmlns:_Document_Definition_1=http://www.abbyy.com/FlexiCapture/Schemas/Export/Document_Definition_1.xsd> <_Page_1> <_First_Name>John</_First_Name> <_Last_Name>Doe</_Last_Name> </_Page_1> </_Document_Definition_1:_Document_Definition_1>
Cutting to the case. Persistence.xml <?xml version=1.0 encoding=UTF-8?> <persistence xmlns=http://java.sun.com/xml/ns/persistence xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd version=2.0>
Given this XML: <?xml version=1.0 encoding=utf-8 ?> <queryableData> <table displayName=Shipments dbName=Quotes> <foreignKey column=CustomerId references=CustomerRegistration/>
I have the following sample XML: <?xml version=1.0 encoding=utf-8 ?> <queryableData> <table displayName=Shipments dbName=Quotes>
I using MSXML4 to generate a XML. I'm trying to set the encoding value
I'm facing a nasty encoding issue when transforming XML via XSLT through PHP. The
There I am trying to load XML content from a remote host using Node.js.
Hello I'm trying to insert some XML data into a table on SQL Server
I want to be able to write XML to a String with the declaration
I'm trying to get my JSP to parse an XML file so that I

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.