locked
xml help RRS feed

  • Question

  • User-974983964 posted

    i have a xml,I want to get the max value from attribute of a node

    Tuesday, December 15, 2015 8:40 AM

Answers

  • User1724605321 posted

    Hi  Melody ,

    i have a xml,I want to get the max value from attribute of a node

    You could use Linq to Xml to achieve that . For example , if  xml like:

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

    If I want to get the max value of FeeGroup ,  code below is for your reference :

                int maxValue = XDocument.Load(@"D:\TEST.xml").Descendants("FeeGroup")
                   .Max(x => (int)x.Attribute("value"));

    Best Regards,

    Nan Yu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 15, 2015 9:02 AM