Ask a Question

how to get proerties value from layered response in Groovy script

SOLVED
easyfish
Contributor

how to get proerties value from layered response in Groovy script

Hello!


I am doing data-driven testing and now working on data tranferring from soapui request/response to oracle table.

With the following groovy, I can get the value of the response, then I can update the responding test data in orable table.

----
import com.eviware.soapui.support.XmlHolder
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext
import groovy.sql.Sql
import oracle.jdbc.driver.OracleTypes

def response=context.expand('${Additional#response}')
log.info response

// get the desired node value from response
def xml=new XmlHolder(response)

def r_Amount=xml.getNodeValue("//Amount")
def r_Base=xml.getNodeValue("//Base")
def r_yRate=xml.getNodeValue("//Rate")

log.info r_Amount +" "+r_Base +" "+r_Rate
-----

When the response has two layers, like below, I can only the get first <amountItem>, how can I get the values under the second <amountItem>?


<amountItems>
    <amountItem>
       <Amount>900.00</Amount>
       <Base>10000.000</Base>
       <Rate>9.000</Rate>
    </amountItem>

    <amountItem>
       <Amount>900.00</Amount>
       <Base>10000.000</Base>
       <Rate>9.000</Rate>
    </amountItem>
</amountItems>


I tried the code and get null.
def r_amountItem=xml.getNodeValue("//amountItem")
log.info r_amountItem

 

2 REPLIES 2
nmrao
Community Hero

Do you want only one? or all?
If only one, then use index like //amountitems/amountitem[1]/Amount.
If you want all, loop thru them.
http://stackoverflow.com/questions/15077592/iterate-through-each-xml-node-with-groovy-printing-each-...


Regards,
Rao.

Thanks a lot for your rapid reply! I got the answer to the question.

cancel
Showing results for 
Search instead for 
Did you mean: