鉴于此 XML
<?xml version="1.0" encoding="UTF-8"?>
<data>
<level0 id="1" t="0" l0id="0">
<level1 id="lev1id01" att1="2015-05-12" val="12" status="0" year="2015" month="05" />
<level1 id="lev1id02" att1="2015-06-13" val="13" status="0" year="2015" month="07" />
<level1 id="lev1id03" att1="2015-07-10" val="13" status="0" year="2015" month="04" />
</level0>
<level0 id="2" t="1" l0id="2">
<level1 id="lev1id21" att1="2015-05-12" val="121" status="0" year="2015" month="05" />
<level1 id="lev1id22" att1="2015-06-13" val="132" status="0" year="2015" month="06" />
<level1 id="lev1id23" att1="2015-07-11" val="113" status="0" year="2015" month="08" />
<level1 id="lev1id24" att1="2015-07-11" val="114" status="0" year="2015" month="07" />
</level0>
</data>
我需要找到按, then和values排序的所有level1
节点(每个节点一个)。level0
att1
year
month
对于这个例子,我希望得到节点:
level1[@id=" lev1id03 "]
level1[@id=" lev1id23 "] -- 因为它具有
month = 08
最大值
我想我必须使用这样的东西:
new XmlSlurper().parseText(xml).level0.level1.findAll {level1 ->
/* some closure */
}
不幸的是,我不是Groovy / GPath专家,所以我正在寻找一种 Groovish 方法来做到这一点。谢谢。