Forum Discussion

Oct21's avatar
Oct21
Occasional Contributor
6 years ago

Need to extract the value of an attribute from response XML

Hi 

 

I want to extract the value of orderItemRef from both assessment and report tag from response 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>

 

Please help.

 

Thanks

Oct21

  • avidCoder's avatar
    avidCoder
    Super 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.

    • Oct21's avatar
      Oct21
      Occasional Contributor

      Hi 

       

      Thanks for responding, but the code above is returning null value.

       

      Thanks

      Oct21

      • avidCoder's avatar
        avidCoder
        Super Contributor

        Please refresh the page.. I have changed the solution.