如何识别在groovy中使用xmlslurper,我的xml中是否存在节点?

时间:2011-05-17 05:47:11

标签: xml groovy

我有这个xml,我想检查price节点是否存在,然后再进行一系列操作。

<game>
 <genre>
  <action>...</action>
  <racing>...</racing>
 <price>
  ..
  ..
  </price>
</genre>
</game>

我怎么能在groovy中实现这个目标?

1 个答案:

答案 0 :(得分:2)

嘿,我得到了答案,这对我来说很好。

xml是GPathResult对象,其中包含xml。

xml.children().find {it.name()=="price"}
如果price存在,

//将返回true