Extract XML data based on Input request

Not applicable

The request comes with an input which is assigned to a variable say "employeeId". Now, when I fire a request at the target I get an xml response. Can I use extract variable something like below:

<XPath>/root/message[empId="{employeeId}"]/empName</XPath>

Response:

<root>
  <message>
    <empId>123</empId>
    <empName>ABC</empName>
  </message>
  <message>
    <empId>456</empId>
    <empName>DEF</empName>
  </message>
</root>
1 1 192
1 REPLY 1

Mmmmm, unfortunately not. You cannot use a dynamic XPath expression today in the ExtractVariables policy.

That would be a nice feature, though! I'll log it as a feature request.

Today the way to do what you want is to use the JS callout and apply the xpath there. You can use the npm module "xpath". You will need to run it through browserify . I tried this and got this result:

$ curl -i https://${ORG}-${ENV}.apigee.net/satyam-xpath-in-js/t1?employeeId=123
HTTP/1.1 200 OK
Date: Mon, 12 Mar 2018 22:10:14 GMT
Content-Type: text/plain
Content-Length: 17
Connection: keep-alive

The value is: ABC

$ curl -i https://${ORG}-${ENV}.apigee.net/satyam-xpath-in-js/t1?employeeId=456
HTTP/1.1 200 OK
Date: Mon, 12 Mar 2018 22:10:22 GMT
Content-Type: text/plain
Content-Length: 17
Connection: keep-alive

The value is: DEF

See the attached working API Proxy. satyam-xpath-in-js-apiproxy.zip