我有这个xml,我想检查price
节点是否存在,然后再进行一系列操作。
<game>
<genre>
<action>...</action>
<racing>...</racing>
<price>
..
..
</price>
</genre>
</game>
我怎么能在groovy中实现这个目标?
答案 0 :(得分:2)
嘿,我得到了答案,这对我来说很好。
xml是GPathResult对象,其中包含xml。
xml.children().find {it.name()=="price"}
如果price
存在,//将返回true