Forum Discussion

marlonumali's avatar
Occasional Contributor
8 years ago

How to verify response content if it has valid DateTime or Decimal value, or if it has no value?

Please help me to correctly determine the data type of the response as it seems that regardless of the actual response value it will always evaluate to a string. Please see the following example which I also got from one of the posting here in smartbear community forum. Thank you.



def xml='''
def groovyUtils = new
def reader = groovyUtils.getXmlHolder(xml )
use (groovy.xml.dom.DOMCategory) {
for( node in reader.getDomNodes( "//node" )) {
   node.children().each { child ->
      if (child.text() instanceof Integer) { child.text() +" is integer"
      } else if (child.text() instanceof Double) { child.text()+" is double"
      } else if (child.text() instanceof Boolean) { child.text()+" is boolean"
      } else if (child.text() instanceof String) { child.text()+" is string"



Fri Feb 13 07:46:03 IST 2015:INFO:1 is string
Fri Feb 13 07:46:03 IST 2015:INFO:12.00 is string
Fri Feb 13 07:46:03 IST 2015:INFO:true is string
Fri Feb 13 07:46:03 IST 2015:INFO:testvalue is string

5 Replies