BruceyBandit BruceyBandit - 3 years ago 263
Groovy Question

how to find an xml tag using groovy

I want to perform a basic if statement where if the xml tag

is not displayed then true, else false, however I keep getting true displayed.

How can i correct the if statement so that if the tag is not displayed, it will output true?

Below is my if statement:

if (xml.'**'.any { != 'b:HotelId' })
{ true
{ false

Rao Rao
Answer Source

Here you go, follow in line comments.

//Find if there is such element, HotelId, in the xml 
def hotelId = xml.'**'.find{ == 'HotelId' }
//The size should be at least 1, so you want to print false
if (hotelId.size()) { 'element found' false
} else {
  //you want to print true 'element not found' true
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download