Forum Discussion

Nagravision_SA__1's avatar
12 years ago

[R]Need to execute the loop on XML Node values

Hi,

In my test scenario, i have a property transfer test step. In this test step i am transferring a publicId value from XML response to another test step. Actually in the xml response there are more than one publicId . My question is that i want to transfer all the publicId values in the XML response to another test step in a loop (one by one). How can i do that ?? Following is the xml response example with more than one id values:-

<ProductTOType xmlns="http://...">
<total_records>2</total_records>
<offset>0</offset>
<version>Unknown</version>
<Product>
<publicId>1206</publicId>
<title>title_CFG</title>
</Product>
<Product>
<publicId>1205</publicId>
<title>title_TBD</title>
</Product>
</ProductTOType>


Thanks in Advance !!

Regards
  • Cizo89's avatar
    Cizo89
    Frequent Contributor
    Hi,

    XmlHolder should do the trick for you.

    Try this:

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def holder = groovyUtils.getXmlHolder( "name_of_your_test#ResponseAsXml" )

    for (publicId in holder.getNodeValues("//publicId")){
    log.info(publicId)
    //here you can use another holder to update the next request or method setPropertyValue(String, String) to create a new property - depends on your requirements
    }


    Regards,
    Marek