xpath - XPath 1.0 获取子记录
问题描述
下面是 XML
<on-error-continue type="APIKIT:BAD_REQUEST" enableNotifications="true" logException="true">
<set-variable value="200" doc:name="httpStatus" variableName="httpStatus" />
<set-variable value="Bad request" doc:name="logDescription" variableName="logDescription" />
<flow-ref doc:name="global-prepare-error-response-sub-flow" name="global-prepare-error-response-sub-flow"/>
</on-error-continue>
<on-error-continue type="APIKIT:TOO_MANY_REQUEST" enableNotifications="true" logException="true">
<set-variable value="200" doc:name="httpStatus" variableName="httpStatus" />
<set-variable value="Many request" doc:name="logDescription" variableName="logDescription" />
<flow-ref doc:name="global-prepare-error-response-sub-flow" name="global-prepare-error-response-sub-flow"/>
</on-error-continue>
想拿到单曲
"set-variable value="200" doc:name="httpStatus" variableName="httpStatus"
使用 xPath 1.0 表达式:父级是 -->on-error-continue type="APIKIT:BAD_REQUEST",子级是 -->set-variable value = "200"。
试过下面的表达。它适用于 Xpath2.0 但不适用于 1.0
//*[local-name()='on-error-continue'][@*[local-name()='type' and .='APIKIT:BAD_REQUEST']]/set-variable[@value='200' and @variableName='httpStatus']
解决方案
使用这个方便的网站,我将 xml 放入根元素中,<root>YOUR XML</root>
.
使用这个 XPath:
//root/on-error-continue[@type='APIKIT:TOO_MANY_REQUEST']/set-variable[@value='200' and @variableName='httpStatus']
我能够提取匹配的记录。自己试试,把上面 XPath 中的root
替换成。*
您应该看到您正在寻找的记录。
通配符运算符可以像路径中的任何元素一样使用。
推荐阅读
- json - 使用 jolt 复制 Json 数组元素
- http - 未处理的异常:FormatException:输入意外结束(在字符 1 处)
- jquery - 当所有子元素都不可见时隐藏父 HTML 内容
- javascript - 在 Javascript/JQuery 中使用自定义分隔符计算天数
- scala - 在 EMR Notebooks 中添加外部 jar
- javascript - RxJS Subject 从来没有推送过第一个 next
- .net - WebBrowser 控件未连接到或呈现 SharePoint 网站
- c# - 如何在运行时通过代码添加迁移
- python - matplotlib 中的对数比例图为零值
- reactjs - 在反应js中使用语义ui的“ui grid”类在多列中显示内容的问题