Forum Discussion
avidCoder
6 years agoSuper Contributor
Try the below code and consider this xml:-
<AssessmentOrder> <Assessment packageTag="A_VAT_Induct" name="Verify - Inductive Reasoning (2007)" orderItemRef="2183404" language="MULTI" stage="1" jobLevel="Graduate/University" originalTimer="00:25:00" adjustedTimer="00:25:00"/> <Report packageTag="A_VAT_Induct" name="Verify - Inductive Reasoning (2007)" orderItemRef="1711998" language="en-US" comparisonGroup="" reportFormat="Pdf" reportMedia="Link"/> <AssessmentAccess hasAssessments="true"> <Assessment stage="1"> </Assessment> </AssessmentAccess> </AssessmentOrder>
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context ) def holder = groovyUtils.getXmlHolder( "Request_Name#Response" ) for( orderItemAssess in holder.getNodeValues( "//*:AssessmentOrder//*:Assessment/@orderItemRef" ))
log.info orderItemAssess
for( orderItemReport in holder.getNodeValues( "//*:AssessmentOrder//*:Report/@orderItemRef" ))
log.info orderItemReport
Now try this code.
- Oct216 years agoOccasional Contributor
Hi
Thanks for responding, but the code above is returning null value.
Thanks
Oct21
- avidCoder6 years agoSuper Contributor
Please refresh the page.. I have changed the solution.
- nmrao6 years agoChampion Level 3
def str = '''<AssessmentOrder> <Assessment packageTag="A_VAT_Induct" name="Verify - Inductive Reasoning (2007)" orderItemRef="2183404" language="MULTI" stage="1" jobLevel="Graduate/University" originalTimer="00:25:00" adjustedTimer="00:25:00"/> <Report packageTag="A_VAT_Induct" name="Verify - Inductive Reasoning (2007)" orderItemRef="1711998" language="en-US" comparisonGroup="" reportFormat="Pdf" reportMedia="Link"/> <AssessmentAccess hasAssessments="true"> <Assessment stage="1"> </Assessment> </AssessmentAccess> </AssessmentOrder>''' def xml = new XmlSlurper().parseText(str) def getOrderRef = { element -> xml.'**'.find {it.name() == element}.@orderItemRef } def elements = ['Assessment', 'Report'] elements.each { log.info getOrderRef(it) }
The above demonstrates with fixed xml.
In order to work for your response, assign the response to 'str' variable i.e., first line.
- Oct216 years agoOccasional Contributor
I tried below code to save my response xml. In my case response xml will always generate new OrderRef.
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context) def str = groovyUtils.getXmlHolder("RegistrationRequest#Response") def xml = new XmlSlurper().parseText(str) def getOrderRef = { element -> xml.'**'.find {it.name() == element}.@orderItemRef } def elements = ['Assessment', 'Report'] elements.each { log.info getOrderRef(it) }
But am getting error. Could you please check?
Thanks,
Oct21
Related Content
Recent Discussions
- 15 years ago