locked
How to find maximum value from XML file using LINQ RRS feed

  • Question

  • User1839056048 posted

    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 using LINQ

    Regards

    Baiju

    Monday, December 14, 2015 7:12 AM

Answers

  • User1724605321 posted

    Hi klbaiju,

    Code below is for your reference :

       var maxResult = XDocument.Load(@"D:\TEST.xml").Descendants("FeegId").Max(x => (int)x);

    Best Regards,

    Nan Yu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 14, 2015 8:45 AM