groovy / xml - 获取具有更大属性值的元素

时间:2014-04-04 08:40:31

标签: xml list groovy

作为一个例子,我用这个例子来解释我想要的东西

<records>
  <car name='HSV Maloo' make='Holden' year='2006'>
    <country>Australia</country>
    <record type='speed'>Production Pickup Truck with speed of 271kph</record>
  </car>
  <car name='P50' make='Peel' year='1962'>
    <country>Isle of Man</country>
    <record type='size'>Smallest Street-Legal Car at 99cm wide and 59 kg in weight</record>
  </car>
  <car name='Royale' make='Bugatti' year='1931'>
    <country>France</country>
    <record type='price'>Most Valuable Car at $15 million</record>
  </car>
</records>

http://groovy.codehaus.org/Reading+XML+using+Groovy的+ XmlParser的

我现在如何能够在指定年份检索汽车入场券,但我不知道如何获得最近一年的入场券。

def records= new XmlParser().parse(xmlFile)

println records.car.find {it.'@name' == 'HSV Maloo' && it.'@year' == '2006'}

1 个答案:

答案 0 :(得分:4)

这应该有效:

println records.car.max { it.@'year'.toInteger() }