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.price as maximum
Here's the sample xml:--
<Results>
<ResultSet fetchSize="0">
<Row rowNumber="1">
<INDEX>86</INDEX>
<INDEX.PRICE>22999.0</INDEX.PRICE>
<INDEX.PRICE1>11999.0</INDEX.PRICE1>
</Row>
<Row rowNumber="2">
<INDEX>90</INDEX>
<INDEX.PRICE>2999.0</INDEX.PRICE>
<INDEX.PRICE1>1299.0</INDEX.PRICE1>
</Row>
<Row rowNumber="3">
<INDEX>92</INDEX>
<INDEX.PRICE>3399.0</INDEX.PRICE>
<INDEX.PRICE1>1399.0</INDEX.PRICE1>
</Row>
<Row rowNumber="4">
<INDEX>100</INDEX>
<INDEX.PRICE>3099.0</INDEX.PRICE>
<INDEX.PRICE1>1598.0</INDEX.PRICE1>
</Row>
<Row rowNumber="5">
<INDEX>116</INDEX>
<INDEX.PRICE>3399.0</INDEX.PRICE>
<INDEX.PRICE1>1399.0</INDEX.PRICE1>
</Row>
<Row rowNumber="6">
<INDEX>160</INDEX>
<INDEX.PRICE>3199.0</INDEX.PRICE>
<INDEX.PRICE1>1299.0</INDEX.PRICE1>
</Row>
<Row rowNumber="7">
<INDEX>161</INDEX>
<INDEX.PRICE>2899.0</INDEX.PRICE>
<INDEX.PRICE1>1499.0</INDEX.PRICE1>
</Row>
</ResultSet>
</Results>
i am using this query to find out the maximum value of index price. What can be done to find out it's index.price1
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def response = context.expand( '${JDBC Request#ResponseAsXml}' )
log.info response
def v=groovyUtils.getXmlHolder("JDBC Request#ResponseAsXml")
def price=v.getNodeValues("//*:INDEX.PRICE")
log.info price.toString()
def maxim= price.max()//to find maximum out from the list
log.info maxim
_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.
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