xpath - xpath 匹配不适用于查询参数
问题描述
我试图在查询参数的 xpath 匹配中放置一个 AND 条件,但是它不起作用。
我正在创建多个存根,其中 uniqueId 可以包含同样的数字 00000 或 11111 但 serviceName 会不同。例如,在第一个请求中,uniqueId 为 1000001 且 serviceName='ABC',在第二个请求中,uniqueId 再次为 1000001 且 serviceName 为 'XYZ'。因为这两种反应会有所不同。我创建了三个存根,一个用于服务 ABC,第二个用于服务 XYZ,第三个是默认的,没有和 xpath 匹配。当我使用包含 uniqueId 1000001 和 serviceName ABC 或 XYZ 的查询参数调用服务时,每次我得到默认存根的响应。在查询参数中传递 xml
"queryParameters":{
"xmlreqdoc": {
"matchesXPath" : "//*[[local-name()='uniqueId'][text()[contains(.,'00000')]] AND //*[local-name()='serviceName'][text() = 'ABCDEFGH']]"
}
}
我已经创建了具有优先级的存根..并且似乎每次都返回默认值。以下是请求xml
<?xml version="1.0" encoding="UTF-8"?>
<service>
<serviceHeader>
<userId>XXXX</userId>
<password>XXXXX</password>
<serviceName>ABCDEFGH</serviceName>
</serviceHeader>
<serviceBody>
<subServiceName>add</subServiceName>
<uniqueId>00000</uniqueId>
</serviceBody>
</service>
下面是我创建的存根映射
{
"priority" : 1,
"request": {
"urlPath": "/testMappings",
"method": "GET",
"headers": {
"Content-Type": {
"equalTo": "application/xml"
},
"Accept": {
"equalTo": "application/xml"
}
},
"queryParameters":{
"xmlreqdoc": {
"matchesXPath" : "//*[//[local-name()='uniqueId'][text()[contains(.,'00000')]] AND //*[local-name()='serviceName'][text() = 'ABCDEFGH']]"
}
}
},
"response": {
"status": 400,
"headers": {
"Content-Type" : "application/xml"
},
"fixedDelayMilliseconds": 500,
"bodyFileName": "ERROR.xml"
}
}
任何帮助或指示将不胜感激。提前致谢!!
解决方案
您已经告诉我们您尝试过的错误语法,但您没有告诉我们您要达到的目标,所以我们可以告诉您您做错了什么,但我们无法告诉您如何实现正确的。
"//*[//[local-name()='uniqueId'][text()[contains(.,'00000')]] AND //*[local-name()='serviceName'][text() = 'ABCDEFGH']]"
这里明显错误的事情:
//
紧随其后的是谓词- 当不涉及命名空间时,在 local-name() 上进行不必要的匹配
- 不必要的使用
text()
- 可以使用时不必要地使用 contains()
=
AND
应该and
也许你想要//uniqueId = '00000' and //serviceName = 'ABCDEFGH'
推荐阅读
- ios - Unable to install pkpass with error Class UpdateAndReportServices is implemented in both
- sql - 在 SQL 中以不同的顺序查找姓名和姓氏
- python - 在 Python 中使用 Selenium 和 chromedriver 进行网页抓取
- javascript - 获取数组属性的 javascript 数组的最小/最大值
- c++ - C ++:如何使用相同的内存空间重新分配数组但大小减小
- java - 为什么 javac 允许一些不可能的强制转换而不是其他强制转换?
- javascript - 我如何更改它之外的样式表属性?反应原生
- python - 使用 BeautifulSoup 获取搜索结果编号
- ocaml - 如何根据 OCAML 中的上下文使参数采用伪“null”值
- google-cloud-firestore - 如何将集合转换为 Firestore 安全规则中的列表?