# Xpath Expression for the Soap response

**URL:** <https://community.gatling.io/t/xpath-expression-for-the-soap-response/3770>\
**Category:** Gatling (Open-Source)\
**Created:** [June 14, 2017, 8:13am UTC](https://community.gatling.io/t/xpath-expression-for-the-soap-response/3770 "2017-06-14T08:13:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gopi\_Krish](https://avatars.discourse-cdn.com/v4/letter/g/c0e974/32.png) [@Gopi\_Krish](https://community.gatling.io/u/Gopi_Krish)\
**Post date:** [June 14, 2017, 8:13am UTC](https://community.gatling.io/t/xpath-expression-for-the-soap-response/3770/1 "2017-06-14T08:13:17Z")

</div>

Hi guys,

The following is the soap response. How to extract this data **bVt7-IgW4-XA2W-w8GS-kbIe-1bth-X3** and store it in a variable TokenValue from the response, using xpath

\<S:Envelope xmlns:S=“[http://schemas.xmlsoap.org/soap/envelope/](http://schemas.xmlsoap.org/soap/envelope/)”\>  
\<S:Body\>  
\<ns2:registerCustomerResponse xmlns:ns2=“[services.evergent.com](http://services.evergent.com)”\>  
  
Nueva Cuenta creada con éxito  
  
cpCustomerId  
170614064308126  
  
  
spAccountId  
170614064308140699918699918  
  
  
orderId  
  
  
  
sessionToken  
**bVt7-IgW4-XA2W-w8GS-kbIe-1bth-X3**  
  
SUCCESS  
  
\</ns2:registerCustomerResponse\>  
\</S:Body\>  
\</S:Envelope\>

i had tried this, but haven’t worked out

.check(xpath("//paramName/paramValue[4]").saveAs(“TokenValue”))

it returned this

---- Errors --------------------------------------------------------------------

---

<div class="post-metadata">

**Author:** ![Barry\_Perez](https://avatars.discourse-cdn.com/v4/letter/b/7ba0ec/32.png) [@Barry\_Perez](https://community.gatling.io/u/Barry_Perez)\
**Post date:** [June 14, 2017, 10:29am UTC](https://community.gatling.io/t/xpath-expression-for-the-soap-response/3770/2 "2017-06-14T10:29:55Z")

</div>

Your xpath is wrong. Suggest working out the correct xpath using an online tool such as [http://www.xpathtester.com/xpath](http://www.xpathtester.com/xpath) first, before incorporating in your Gatling script.

Using ordinals, this would get the value you’re after:

**//params[4]/paramValue**

However, using ordinals is not a good idea because you can’t always guarantee that the fields will not appear in the correct format (depending on schema), or that the response won’t change in future (i.e. if a field gets inserted).

This is a better xpath for what value you’re after:

**//params[paramName=‘sessionToken’]/paramValue**

Even more efficient would be to use a more explicit XPath, but since there are different namespaces involved that would involve a bit of messing about with the query, which I can’t be bothered to look at - so suggest using the non-ordinal option above.

Cheers,  
Barry

---

<div class="post-metadata">

**Author:** ![Gopi\_Krish](https://avatars.discourse-cdn.com/v4/letter/g/c0e974/32.png) [@Gopi\_Krish](https://community.gatling.io/u/Gopi_Krish)\
**Post date:** [June 15, 2017, 10:26am UTC](https://community.gatling.io/t/xpath-expression-for-the-soap-response/3770/3 "2017-06-15T10:26:02Z")

</div>

Thanks a lot Barry, the code you suggested Worked out. 😄
