0

この 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>

すべてのlevel1ノード (ノードごとに 1 つ) を、 then 、および の値でlevel0並べ替える必要があります。att1yearmonth

この例では、ノードを取得することを期待しています:

  • level1 [@id=" lev1id03 "]

  • level1 [@id=" lev1id23 "] --month = 08どれが最大かを持っているため

次のようなものを使用する必要があると思います。

new XmlSlurper().parseText(xml).level0.level1.findAll {level1 -> 
    /* some closure */
}

残念ながら、私はGroovy / GPathの専門家ではないので、Groovish の方法を探しています。ありがとう。

4

0 に答える 0