Forum Discussion

_lauren11's avatar
_lauren11
Occasional Contributor
5 years ago
Solved

How to fetch a value of the node when given the condition

From the given index.price in all the nodes, i am able to find out the index.price having maximum value. My query is, how to find out the value of index.price1, from the node which is having index.pr...
  • HimanshuTayal's avatar
    HimanshuTayal
    5 years ago

    _lauren11 : Yes now i get the better understanding. Please use below code,

     

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def response = context.expand( '${JDBC Request#ResponseAsXml}' )
    def v=groovyUtils.getXmlHolder(response)
    def price=v.getNodeValues("//Row")
    def desiredVal, maxVal
    List<Double> values = new ArrayList<Double>();
    for( item in v.getNodeValues( "//Row/INDEX.PRICE" )){
    	values.add( Double.parseDouble(item) );
    }
    maxVal =  values.max()
    
    for(int i = 0 ; i < price.size() ; i++){
    	if( v.getNodeValues( "//Row/INDEX.PRICE" )[i] == "$maxVal" ){
    		desiredVal = v.getNodeValues( "//Row/INDEX.PRICE1" )[i]
    	}
    }
    log.info desiredVal.toString()
    

     

    Hope it will solve your problem.

     

     

  • nmrao's avatar
    5 years ago

    _lauren11 

     

    Here you go:

    //Pass the jdbc response xml into jdbcResult variable.
    
    log.info new XmlSlurper().parseText(jdbcResult).'**'.find {it.name() == 'Row' && it.'INDEX.PRICE'.max()}.'INDEX.PRICE1'.text()

     

    You can test it online here

    https://ideone.com/xXgmDh