AabinGunz
AabinGunz

Reputation: 12347

How to identify using xmlslurper in groovy, whether a node exists in my xml?

I have this xml, I want to check the existence of price node if present then do set of actions else move on.

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

How can I achieve this in groovy?

Upvotes: 2

Views: 4375

Answers (1)

AabinGunz
AabinGunz

Reputation: 12347

Hey I got the answer, this works fine for me.

xml is the GPathResult object that has the xml in it.

xml.children().find {it.name()=="price"}

//will return true if price exists

Upvotes: 2

Related Questions