属性名を使用して属性値のリストを取得する GPath 式を探します。
def xmltxt = """<reports>
<report category="weather">sunny</report>
<report category="sports">golf</report>
<report category="business">
<subreport category="deals">wallstreet</subreport>
</report>
<report>NA</report>
<report category="life">gossip</report>
</reports>"""
..すべての属性を検索するとき、属性がドキュメント内category
のどこに存在するかに関係なく、これを取得したい:category
[weather, sports, business, deals, life]
category
...しかし、私の試みはすべて、私が望む以上のものを取得します。属性を持たないノードを返しているようです。リストから空の要素を削除できますが、なぜこれが起こっているのか知りたいです。
[, weather, sports, business, deals, , life]
def names = xml.'**'.findAll{
it.@category
}.collect{
it.@category
}