寻找 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
}