Forum Discussion

rohit330's avatar
rohit330
Visitor
10 years ago

How to read ID values from elements & echo in mockRespose

Hi Team,

I am trying to read id values from the request and echo the same in the response id. parentTag occurance is 1...n. In the response also, parentTage will be send back with same id value. Please let me know how to read idValue1 & idValue2

<ns2:TAG>
<ns2:parentTag id="idValue1">
<ns2:subTag xsi:type="ns2:" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns2:childTag></ns2:childTag>
</ns2:subTag>
</ns2:parentTag>
<ns2:parentTag id="idValue2">
<ns2:subTag xsi:type="ns2:" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns2:childTag></ns2:childTag>
</ns2:subTag>
</ns2:parentTag>
</ns2:TAG>

I tried with the following code. But doesn't seems to be working.

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context)
def holder = groovyUtils.getXmlHolder(mockRequest.requestContent)
for( item in holder.getNodeValues( "//searchArrangementLocationRequest" ))
{ def id = String.valueOf(holder["//searchArrangementLocationRequest//@id"])
log.info id
}

1 Reply

  • nmrao's avatar
    nmrao
    Champion Level 3
    Not sure if you posted the complete response.

    Because you were trying to lookfor element "searchArrangementLocationRequest" which could not be seen in the response shown.

    Would you please post the complete response. And request too if you want to compare the values from request as well which help other to help you.