xpath - 如何在 WSO2 EI 6.1.1 中从soap Payload 中检索元素
问题描述
我有以下来自 WSO2 DSS 端点的肥皂有效载荷。
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<Response xmlns="http://ws.wso2.org/dataservice">
<RestrictionCount>
<count>1</count>
</RestrictionCount>
</Response>
</soapenv:Body>
</soapenv:Envelope>
我想从上面的有效载荷中提取计数值。我通过使用在线 xpath 表达式工具尝试了类似“//RestrictionCount/count/text()”,它给了我结果,但是在编码中我尝试了同样的方法,使用下面的属性中介表达式,这对我不起作用
<property expression="//RestrictionCount/count/text()" name="count" scope="default" type="STRING"/>
谁能帮我解决这个问题?
解决方案
由于您正在处理名称空间,请使用local-name()
选择元素:
<property expression="//*[local-name()='RestrictionCount']/*[local-name()='count']/text()" name="count" scope="default" type="STRING"/>
或者更好的是,在 XPath 表达式之前正确声明命名空间:
<property xmlns:ns="http://ws.wso2.org/dataservice" expression="//ns:RestrictionCount/ns:count/text()" name="count" scope="default" type="STRING"/>
推荐阅读
- javascript - 当网页的输入元素位于影子 dom 内时,用于跟踪文件上传的 chrome 扩展?
- pycharm - PyCharm PyTest:未找到测试对象
- javascript - 如何在不下载 javascript 的情况下访问 csv
- python - 一个接一个地运行python脚本,没有任何中断
- python - 如何向 Django 类添加方法以转换为字典
- maven - 如何配置 maven post-man 插件以包含具有动态名称的附件目录?
- python - 如何检查数字是否在多个范围内?
- regex - PowerShell:使用通配符从变量中删除文本
- laravel - 错误 composer install 在 laravel 脚本之后,在迁移到 php 8 和 laravel 8.4 之后 - 该进程已用信号“11”发出信号
- wordpress - 将自定义样式添加到没有子主题的古腾堡编辑器