[PR #1005] [MERGED] Support for xml namespaces in XPathMatcher #1188

Closed
opened 2025-12-29 16:18:57 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/wiremock/WireMock.Net/pull/1005
Author: @cal-schleupen
Created: 9/29/2023
Status: Merged
Merged: 10/2/2023
Merged by: @StefH

Base: masterHead: XmlNamespaceSupport-XPathMather


📝 Commits (4)

  • 76afc08 Support for xml namespaces in XPathMatcher
  • 523388a Review findings of Stef implemented.
  • 9eed408 Fix of build error
  • 1d3445b New review findings by Stef

📊 Changes

6 files changed (+238 additions, -24 deletions)

View changed files

📝 src/WireMock.Net.Abstractions/Admin/Mappings/MatcherModel.cs (+4 -0)
src/WireMock.Net.Abstractions/Admin/Mappings/XmlNamespace.cs (+21 -0)
📝 src/WireMock.Net/Matchers/XPathMatcher.cs (+77 -22)
📝 src/WireMock.Net/Serialization/MatcherMapper.cs (+6 -1)
📝 test/WireMock.Net.Tests/Matchers/XPathMatcherTests.cs (+67 -1)
📝 test/WireMock.Net.Tests/Serialization/MatcherMapperTests.cs (+63 -0)

📄 Description

We have round about 4800 WCF Services in our landscape, thus this faker is really helpful. In order to write more easy request body matchers I would like to write more easy xpath expressions using the xpath matcher as follows:

{
    "Title": "wcf test",
    "Request": {
        "Path": {
            "Matchers": [
                {
                    "Name": "WildcardMatcher",
                    "Pattern": "/MyService.svc"
                }
            ]
        },
        "Methods": [
            "post"
        ],
                "Headers": [
                    {
                        "Name": "Content-Type",
                        "Matchers": [
                            {
                                "Name": "WildcardMatcher",
                                "Pattern": "text/xml; charset=utf-8",
                                "IgnoreCase": true
                            }
                        ],
                        "IgnoreCase": true
                    },
                    {
                        "Name": "SOAPAction",
                        "Matchers": [
                            {
                                "Name": "WildcardMatcher",
                                "Pattern": "*urn://MyService/Query*",
                                "IgnoreCase": true
                            }
                        ],
                        "IgnoreCase": true
                    }
                ],
        "Body": {
            "Matcher": {
                "Name": "XPathMatcher",
                "Pattern": "/s:Envelope/s:Body/q:QueryRequest",
                "XmlNamespaceMap": [
                    { 
                        "Prefix": "s",
                        "Uri": "http://schemas.xmlsoap.org/soap/envelope/"
                    },
                    { 
                        "Prefix": "i",
                        "Uri": "http://www.w3.org/2001/XMLSchema-instance"
                    },
                    { 
                        "Prefix": "q",
                        "Uri": "urn://Schleupen.AS.MT.BIB.Buecher.BuchQueryService_3.1"
                    }
                ]
            }
        }
    },
    "Response": {
        "StatusCode": 200,
        "Body": "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><QueryResponse xmlns=\"urn://MyService\"></QueryResponse></s:Body></s:Envelope>",
        "Headers": {
            "Content-Type": "text/xml"
        }
    }
}

This implementation handles this so that

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Header></s:Header><s:Body><QueryRequest xmlns="urn://MyService"><MaxResults i:nil="true" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"/><Restriction i:nil="true" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"/><SearchMode i:nil="true" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"/></QueryRequest></s:Body></s:Envelope> 

matches for example.

Yes, I can use 'local-name()' etc. but I think this way it is more easy.


🔄 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/1005 **Author:** [@cal-schleupen](https://github.com/cal-schleupen) **Created:** 9/29/2023 **Status:** ✅ Merged **Merged:** 10/2/2023 **Merged by:** [@StefH](https://github.com/StefH) **Base:** `master` ← **Head:** `XmlNamespaceSupport-XPathMather` --- ### 📝 Commits (4) - [`76afc08`](https://github.com/wiremock/WireMock.Net/commit/76afc0895bbb41f1d601c6fe2e6d34ef30981f42) Support for xml namespaces in XPathMatcher - [`523388a`](https://github.com/wiremock/WireMock.Net/commit/523388a787bc0ffc830f86a6c405f5e4a9ce8385) Review findings of Stef implemented. - [`9eed408`](https://github.com/wiremock/WireMock.Net/commit/9eed408fc64ca26a890dc8a53db97814851ab31f) Fix of build error - [`1d3445b`](https://github.com/wiremock/WireMock.Net/commit/1d3445b0f393fcaa786ae8500960c9b6047e333c) New review findings by Stef ### 📊 Changes **6 files changed** (+238 additions, -24 deletions) <details> <summary>View changed files</summary> 📝 `src/WireMock.Net.Abstractions/Admin/Mappings/MatcherModel.cs` (+4 -0) ➕ `src/WireMock.Net.Abstractions/Admin/Mappings/XmlNamespace.cs` (+21 -0) 📝 `src/WireMock.Net/Matchers/XPathMatcher.cs` (+77 -22) 📝 `src/WireMock.Net/Serialization/MatcherMapper.cs` (+6 -1) 📝 `test/WireMock.Net.Tests/Matchers/XPathMatcherTests.cs` (+67 -1) 📝 `test/WireMock.Net.Tests/Serialization/MatcherMapperTests.cs` (+63 -0) </details> ### 📄 Description We have round about 4800 WCF Services in our landscape, thus this faker is really helpful. In order to write more easy request body matchers I would like to write more easy xpath expressions using the xpath matcher as follows: ``` json { "Title": "wcf test", "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/MyService.svc" } ] }, "Methods": [ "post" ], "Headers": [ { "Name": "Content-Type", "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "text/xml; charset=utf-8", "IgnoreCase": true } ], "IgnoreCase": true }, { "Name": "SOAPAction", "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "*urn://MyService/Query*", "IgnoreCase": true } ], "IgnoreCase": true } ], "Body": { "Matcher": { "Name": "XPathMatcher", "Pattern": "/s:Envelope/s:Body/q:QueryRequest", "XmlNamespaceMap": [ { "Prefix": "s", "Uri": "http://schemas.xmlsoap.org/soap/envelope/" }, { "Prefix": "i", "Uri": "http://www.w3.org/2001/XMLSchema-instance" }, { "Prefix": "q", "Uri": "urn://Schleupen.AS.MT.BIB.Buecher.BuchQueryService_3.1" } ] } } }, "Response": { "StatusCode": 200, "Body": "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><QueryResponse xmlns=\"urn://MyService\"></QueryResponse></s:Body></s:Envelope>", "Headers": { "Content-Type": "text/xml" } } } ``` This implementation handles this so that ``` xml <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Header></s:Header><s:Body><QueryRequest xmlns="urn://MyService"><MaxResults i:nil="true" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"/><Restriction i:nil="true" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"/><SearchMode i:nil="true" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"/></QueryRequest></s:Body></s:Envelope> ``` matches for example. Yes, I can use 'local-name()' etc. but I think this way it is more easy. --- <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 16:18:57 +01:00
adam closed this issue 2025-12-29 16:18:57 +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#1188