find the maximum value of field from xml using linq [Resolved]

Posted by Klbaiju under LINQ on 12/14/2015 | Points: 10 | Views : 434 | Status : [Member] | Replies : 2
Hi,

I want to find the maximum value of a particular field from XML file.

following is my XML file

<?xml version="1.0" encoding="utf-8"?>
<FeeGroups>
<FeeGroup>
<FeegId>100</FeegId>
<Fgname>sss</Fgname>
<FgDetail>dgdgdgdg</FgDetail> /&gt;
</FeeGroup>
<FeeGroup>
<FeegId>101</FeegId>
<Fgname>sss1</Fgname>
<FgDetail>rtrtrt</FgDetail>
</FeeGroup>
<FeeGroup>
<FeegId>102</FeegId>
<Fgname>sss2</Fgname>
<FgDetail>klklkl</FgDetail>
</FeeGroup>
<FeeGroup>
<FeegId>103</FeegId>
<Fgname>sss3</Fgname>
<FgDetail>mnmnmn</FgDetail>
</FeeGroup>

</FeeGroups>

my requirement is to fetch the maximum value of FeegId from the above xml


Regards

Baiju




Responses

Posted by: Rajnilari2015 on: 12/14/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
try


doc.Descendants("FeeGroups").Descendants("FeeGroup").Max(m => (int)m.Element("FeegId"));


OR

doc.Descendants("FeeGroups").Descendants("FeeGroup").Select(s => s.Element("FeegId").Value).Max();


OR

doc.Descendants("FeeGroups").Descendants("FeeGroup").Select(s => s.Element("FeegId").Value).OrderByDescending(o => o).First();


OR

doc.Descendants("FeeGroups").Descendants("FeeGroup").Select(s => s.Element("FeegId").Value).OrderBy(o => o).Last();


--
Thanks & Regards,
RNA Team

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: PROFESSIONALUSER on: 12/14/2015 [Member] [MVP] Bronze | Points: 25

Login to post response