[PR #398] [MERGED] Feature/xpath transformer #893

Closed
opened 2025-12-29 15:34:03 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/wiremock/WireMock.Net/pull/398
Author: @kashifsoofi
Created: 1/8/2020
Status: Merged
Merged: 1/9/2020
Merged by: @StefH

Base: masterHead: feature/xpath_transformer


📝 Commits (3)

  • 9fa5a12 XPath transformer, added handlerbars helper to select nodes using xpath and setting the outerxml value in response
  • 65da52a Added test to select attribute value and node text
  • 59a65e7 Removed extra empty lines

📊 Changes

3 files changed (+270 additions, -0 deletions)

View changed files

📝 src/WireMock.Net/Transformers/HandleBarsHelpers.cs (+2 -0)
src/WireMock.Net/Transformers/HandleBarsXPath.cs (+102 -0)
test/WireMock.Net.Tests/ResponseBuilders/ResponseWithHandlebarsXPathTests.cs (+166 -0)

📄 Description

Fixes #397 Added feature to select values from xml using XPath.
Implemented following as suggested

  • XPath.SelectSingleNode
  • XPath.SelectNodes
    Also implemented
  • XPath.Evaluate

Reason for using OuterXml in HandleBarsXPath.cs is as follows but happy to change :
Testing

<todo-list>
  <todo-item id='a1'>abc</todo-item>
  <todo-item id='a2'>def</todo-item>
  <todo-item id='a3'>xyz</todo-item>
</todo-list>

with /todo-list/todo-item[1] results in <todo-item id="a1">abc</todo-item>
using https://www.freeformatter.com/xpath-tester.html. I think it is the correct behaviour as to select text I would provide /todo-list/todo-item[1]/text(). However same experssion return only the text using XPath2SelectSingleNode.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/wiremock/WireMock.Net/pull/398 **Author:** [@kashifsoofi](https://github.com/kashifsoofi) **Created:** 1/8/2020 **Status:** ✅ Merged **Merged:** 1/9/2020 **Merged by:** [@StefH](https://github.com/StefH) **Base:** `master` ← **Head:** `feature/xpath_transformer` --- ### 📝 Commits (3) - [`9fa5a12`](https://github.com/wiremock/WireMock.Net/commit/9fa5a12d648e33b0956e18565215d37bc3767fed) XPath transformer, added handlerbars helper to select nodes using xpath and setting the outerxml value in response - [`65da52a`](https://github.com/wiremock/WireMock.Net/commit/65da52a8cf987ce8dd225babcb31c9104c094673) Added test to select attribute value and node text - [`59a65e7`](https://github.com/wiremock/WireMock.Net/commit/59a65e74d803f9c4115d05f94cafd02650d0cb70) Removed extra empty lines ### 📊 Changes **3 files changed** (+270 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `src/WireMock.Net/Transformers/HandleBarsHelpers.cs` (+2 -0) ➕ `src/WireMock.Net/Transformers/HandleBarsXPath.cs` (+102 -0) ➕ `test/WireMock.Net.Tests/ResponseBuilders/ResponseWithHandlebarsXPathTests.cs` (+166 -0) </details> ### 📄 Description Fixes #397 Added feature to select values from xml using XPath. Implemented following as suggested - `XPath.SelectSingleNode` - `XPath.SelectNodes` Also implemented - `XPath.Evaluate` Reason for using OuterXml in `HandleBarsXPath.cs` is as follows but happy to change : Testing ``` <todo-list> <todo-item id='a1'>abc</todo-item> <todo-item id='a2'>def</todo-item> <todo-item id='a3'>xyz</todo-item> </todo-list> ``` with `/todo-list/todo-item[1]` results in `<todo-item id="a1">abc</todo-item>` using https://www.freeformatter.com/xpath-tester.html. I think it is the correct behaviour as to select text I would provide `/todo-list/todo-item[1]/text()`. However same experssion return only the text using XPath2SelectSingleNode. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 15:34:03 +01:00
adam closed this issue 2025-12-29 15:34:03 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#893