【问题标题】:XPath 1.0 fetch the child recordXPath 1.0 获取子记录
【发布时间】:2021-07-17 13:45:35
【问题描述】:

下面是 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']

【问题讨论】:

    标签: xpath


    【解决方案1】:

    使用这个handy website,我将xml 放入根元素&lt;root&gt;YOUR XML&lt;/root&gt;

    使用这个 XPath:

    //root/on-error-continue[@type='APIKIT:TOO_MANY_REQUEST']/set-variable[@value='200' and @variableName='httpStatus']
    

    我能够提取匹配记录。自己尝试一下,将上面 XPath 中的root 替换为*。您应该会看到您正在寻找的记录。

    通配符运算符可以像路径中的任何元素一样使用。

    【讨论】:

    • 干杯!我进行了相应的修改并得到了预期的结果。这是我获得结果的最终版本 //*[local-name()='on-error-continue'][@type='APIKIT:TOO_MANY_REQUEST']/*[local-name()='set-variable '][@variableName='httpStatus' 和 @value!='200']
    猜你喜欢
    • 2013-06-12
    • 1970-01-01
    • 2019-02-21
    • 2015-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多