Wiremock:如果存在 xmlns,则 xpath 不工作

Wiremock: xpath not working if xmlns is present

我正在 wiremock 中创建存根。如果我在 xml 中有 xmlns,那么它不匹配,但没有它就可以工作。

要求

curl -d '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><a xmlns="http://www.example.com/namespaces/ad"><b>1</b><c>2</c><d>9407339517</d></a>' -i -H "Content-Type: text/xml" -X POST "http://localhost:8080/test"

存根Json

{
  "request": {
    "method": "POST",
    "url": "/test",
    "headers" : {
      "Content-Type" : {
          "equalTo" : "text/xml"
      }
    },
    "bodyPatterns" : [ {
      "matchesXPath" : "/stuff:a[b='1'][c='2']",
      "xPathNamespaces" : {
        "stuff" : "http://www.example.com/namespaces/ad"
      }
    } ]
   },
  "response": {
    "body": "Hello world!",

    "status": 200
  }

}

除了上面提到的方式,我也尝试过local-name()。

当(大)父级存在命名空间时,(大)子级将继承相同的命名空间。所以你的 /b/c 应该以 /stuff:b/stuff:c

作为前缀
{
  "request": {
    "method": "POST",
    "url": "/test",
    "headers" : {
      "Content-Type" : {
          "equalTo" : "text/xml"
      }
    },
    "bodyPatterns" : [ {
      "matchesXPath" : "/stuff:a[./stuff:b='1'][./stuff:c='2']",
      "xPathNamespaces" : {
        "stuff" : "http://www.example.com/namespaces/ad"
      }
    } ]
   },
  "response": {
    "body": "Hello world!",

    "status": 200
  }

}