Given this 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>
I need to find all level1
nodes (one per each level0
node) sorted by att1
, then year
and month
values.
For this example I expect to get nodes:
level1[@id="lev1id03"]
level1[@id="lev1id23"] -- because it has
month = 08
which is maximum
I suppose I have to use something like this:
new XmlSlurper().parseText(xml).level0.level1.findAll {level1 ->
/* some closure */
}
Unfortunately I'm not an Groovy/GPath expert so I'm looking for a Groovish way to do it. Thanks.