Question/Feature: Add support for selecting XPath in response template #239

Closed
opened 2025-12-29 15:18:56 +01:00 by adam · 3 comments
Owner

Originally created by @kashifsoofi on GitHub (Jan 8, 2020).

Originally assigned to: @StefH, @kashifsoofi on GitHub.

Hi,
I am looking to transform soap response. And it would be good if i can use the XPath to select values from request. I believe it can be done using regex but XPath would be a natural fit for this use case.

Question: Is it already supported?

If not happy to do a PR. It would be similar to how json template work.
"{{XPath.Select request.body "/todo-list/todo-item[1]/text()"}}") to return text of 1st element in response.

Originally created by @kashifsoofi on GitHub (Jan 8, 2020). Originally assigned to: @StefH, @kashifsoofi on GitHub. Hi, I am looking to transform soap response. And it would be good if i can use the XPath to select values from request. I believe it can be done using regex but XPath would be a natural fit for this use case. Question: Is it already supported? If not happy to do a PR. It would be similar to how json template work. "{{XPath.Select request.body \"/todo-list/todo-item[1]/text()\"}}") to return text of 1st element in response.
adam added the feature label 2025-12-29 15:18:56 +01:00
adam closed this issue 2025-12-29 15:18:56 +01:00
Author
Owner

@StefH commented on GitHub (Jan 8, 2020):

This is not yet supported, this could be a valuable addition.
Suggested 2 methods:

  • XPath.SelectSingleNode
  • XPath.SelectNodes

I'll take a look at the code how to implement this.

@StefH commented on GitHub (Jan 8, 2020): This is not yet supported, this could be a valuable addition. Suggested 2 methods: - `XPath.SelectSingleNode` - `XPath.SelectNodes` I'll take a look at the code how to implement this.
Author
Owner

@kashifsoofi commented on GitHub (Jan 8, 2020):

I am happy to do a PR for this if okay.

@kashifsoofi commented on GitHub (Jan 8, 2020): I am happy to do a PR for this if okay.
Author
Owner

@StefH commented on GitHub (Jan 8, 2020):

You can make a PR. For reference see the https://github.com/WireMock-Net/WireMock.Net/blob/master/src/WireMock.Net/Transformers/HandleBarsJsonPath.cs file.

Also make sure to add unit-tests for this new transformer. For reference, see https://github.com/WireMock-Net/WireMock.Net/blob/master/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithHandlebarsJsonPathTests.cs

@StefH commented on GitHub (Jan 8, 2020): You can make a PR. For reference see the https://github.com/WireMock-Net/WireMock.Net/blob/master/src/WireMock.Net/Transformers/HandleBarsJsonPath.cs file. Also make sure to add unit-tests for this new transformer. For reference, see https://github.com/WireMock-Net/WireMock.Net/blob/master/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithHandlebarsJsonPathTests.cs
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#239