使用 XPath 检查 Soap Envelope 是否包含子节点 [英] Using XPath to Check if Soap Envelope Contains Child Node

查看:31
本文介绍了使用 XPath 检查 Soap Envelope 是否包含子节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试确定肥皂信封主体是否包含特定节点.

I'm trying to determine if a soap envelope body contains a particular node.

我正在使用的信封示例:

An example of the envelope I'm working with:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <Response>
            <Result>Failure</Result>
            <Error id="40020" value="">An Unkown Error Occured</Error>
        <Response>
    </soapenv:Body>
</soapenv:Envelope>

我想检查是否包含节点响应",以便我可以对其执行条件操作.我对 XPath 比较陌生,所以我不确定完整的表达式应该是什么.

I want to check if the contains the node "Response" so I can perform conditional operations on it as a result. I'm relatively new to XPath, so I'm not sure what the full expression should be.

我目前拥有的 XPath 表达式是

The XPath expression I currently have is

[name(//soapenv:Body/*[1]) = 'Response']

我知道 name(//soapenv:Body/*[1]) 会返回Response"的值,我只是不知道如何将该结果与另一个值进行比较并返回 true/false.

I know name(//soapenv:Body/*[1]) will return the value of "Response", I just don't know how to compare that result to another value and return true/false.

也许像这样的替代表达方式?

Maybe something like this as an alternative expression?

//soapenv:Body/*[contains(Name, "Response")]

推荐答案

试试这些:

//soapenv:Body/*[name()='Response']

或者如果 Response 可以比 Body 的孩子更深(不应该是这种情况)

Or if Response can be deeper than just child of Body (should not be the case)

//soapenv:Body/descendant::*[name()='Response']

这篇关于使用 XPath 检查 Soap Envelope 是否包含子节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆