I am trying to extract line-item value from the below request body into my response in wiremock.
Request:
**<request>
<lineItem>
<item>
<name> name </name>
<quantity> 12 </quantity>
<type>type</type>
</item>
</ lineItem>
<lineItem>
<item>
<name> name2 </name>
<quantity> 10 </quantity>
<type>type2</type>
</item>
</ lineItem>
</request>**
Expected Response:
**<response>
<lineItem>
<item>
<name> name </name>
<quantity> 12 </quantity>
<type>type</type>
</item>
</ lineItem>
<lineItem>
<item>
<name> name2 </name>
<quantity> 10 </quantity>
<type>type2</type>
</item>
</ lineItem>
</response>**
I tried something like this:
<response>
{{#each (xPath request.body '/lineItem/item ') as |element| }}
<lineItem>
<item>
<quantity> (xPath request.body '//lineItem/item/quantity/text()'}}</quantity>
</item>
</ lineItem>
</response>
but for 2 different lineItem in request (as given above), I got 3 lineItem values in response and always getting the first item values in all the 3 lineItems:
Response I got:
**<response>
<lineItem>
<item>
<quantity> 12 </quantity>
</item>
</ lineItem>
<lineItem>
<item>
<quantity> 12 </quantity>
</item>
</ lineItem>
<lineItem>
<item>
<quantity> 12 </quantity>
</item>
</ lineItem>
</response>**
Can someone help me with this scenario?
I ran into a similar problem today. I also needed to get a list of values from a request and create in response as many objects based on this as I received.
If we shift the solution to your question, then it will looks like this: