Groovy GPath按条件查找所有子节点

时间:2016-08-13 00:53:16

标签: groovy collections xml-parsing gpath

鉴于此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排序的所有level0个节点(每个att1节点一个),然后yearmonth值。

对于这个例子,我希望得到节点:

  • 1级[@id =&#34;的 lev1id03 &#34]

  • level1 [@id =&#34; lev1id23 &#34;] - 因为month = 08最多

我想我必须使用这样的东西:

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

不幸的是,我不是 Groovy / GPath 专家,所以我正在寻找一种Groovish方式来做这件事。 感谢。

0 个答案:

没有答案