Forum Discussion

baruA's avatar
baruA
Occasional Contributor
12 years ago

Extract Values from Soap XML response

I am comparing results from soap Response with JDBC response and added an Xpath expression but its keeping getting failed. Could anybody help me please and Thanks in advance.

Soap Response:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<InsertXXXXValueResponse xmlns="namespace">
<InsertXXXXValueResult>&lt;?xml version="1.0" encoding="utf-16"?>
&lt;XXXXValues>
&lt;XXXXValue Uid="2130" ValueCost="10" ValueDescription="ws test22" DailyUses="1" WebAvailableStartDate="9/3/2013" WebAvailableEndDate="9/15/2013" WebSalesLimit="2" WebSalesCount="0" WebTransactionLimit="2" WebSalesPriority="-2147483648" IgnoreWebSalesPriority="Yes" ReportTemplate="XXXX.rpt" />
&lt;/XXXXValues></InsertXXXXValueResult>
</InsertXXXXValueResponse>
</soap:Body>
</soap:Envelope>

JDBC Response:
<Results>
<ResultSet fetchSize="10">
<Row rowNumber="1">
<XXXX_VALUE_UID>2130</XXXX_VALUE_UID>
<EVA_XXXX_VALUE_COST>10</EVA_XXXX_VALUE_COST>
<EVA_XXXX_VALUE_DESCR>ws test22</EVA_XXXX_VALUE_DESCR>
<EVA_DAILY_USES>1</EVA_DAILY_USES>
<EVA_AVAIL_STARTDATE>2013-09-03 00:00:00.0</EVA_AVAIL_STARTDATE>
<EVA_AVAIL_ENDDATE>2013-09-15 23:59:59.0</EVA_AVAIL_ENDDATE>
<EVA_WEB_SALES_LIMIT>2</EVA_WEB_SALES_LIMIT>
<EVA_WEB_TRANSACTION_LIMIT>2</EVA_WEB_TRANSACTION_LIMIT>
<CRT_UID_PERMIT_REPORT>2702</CRT_UID_PERMIT_REPORT>
<CRT_TEMPLATE_NAME>XXXX.rpt</CRT_TEMPLATE_NAME>
</Row>
</ResultSet>
</Results>

Xpath Expression: declare namespace ns1='XXXX/';
//ns1:InsertxxxValueResponse[1]
declare namespace ns1='namespace/';
<InsertxxxValueResult>&lt;?xml version="1.0" encoding="utf-16"?>
//ns1:${JDBC Request#ResponseAsXml#//Results[1]/ResultSet[1]/Row[1]}

I am getting the below error on testing the assertion:

XPathContains comparison failed, expecting [declare namespace ns1=namespace/'; <?xml version="1.0" encoding="utf-16"?> //ns1: 2130 10 ws test22 1 2013-09-03 00:00:00.0 2013-09-15 23:59:59.0 2 2 2702 xxx.rpt ], actual was [ ]
  • SiKing's avatar
    SiKing
    Community Expert
    Skip/delete the part about "declare namespace", and use "*" instead. So your XPath expression would look something like:
    //*:XXXXValue/@Uid
    which should equal the expected value:
    ${JDBC Response#ResponseAsXml#//XXXX_VALUE_UID}
  • Hi,

    Similar fashion , I have a scenario where I was to get the XPATH values from properties then pass on to the groovy to find the node values. But I am getting no response... Please guide

    Property contains value aa = *.CelciusToFahrenheitResult
    ------------------------------ below is the groovy where I am trying to fetch the value from the response----------------
    def props=testRunner.testCase.getTestStepByName("Properties")
    value = props.getPropertyValue("aa")
    log.info ("This is value" + "$value" ) // This displays the correct value in log ( *.CelciusToFahrenheitResult)

    globalAuthTransfer =context.expand('${CelciusToFahrenheit#Response#value}')

    log.info ("This is response" + globalAuthTransfer) // This gives a blank response insted it should give the value from the result.

    Note;- I have also tried using $value as well in the above step but no luck. Please guide.

    Thanks,
    manoj
  • nmrao's avatar
    nmrao
    Icon for Champion Level 2 rankChampion Level 2
    Understand that CelciusToFahrenheit is the step name and looking for capturing its response.
    May be you try like below and also you can refer http://www.soapui.org/Scripting-Propert ... rate-nodes

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