rohit330
11 years agoVisitor
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
}
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
}