我有几个肥皂输入,并希望根据有效载荷中元素的存在来决定我的骡流程中的行动方案。
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xyz="http://xyz.abc.com/">
<soapenv:Header/>
<soapenv:Body>
<xyz:myFirst/>
</soapenv:Body>
</soapenv:Envelope>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xyz="http://xyz.abc.com/">
<soapenv:Header/>
<soapenv:Body>
<xyz:mySecond>
Something here
</xyz:mySecond>
</soapenv:Body>
</soapenv:Envelope>
在上述有效载荷中,如果存在“myFirst”,我想走一条路线,如果“mySecond”存在,则另一条路线。
我尝试了以下
<choice>
<when expression="#[xpath('fn:count(//soapenv:Envelope/soapenv:Body/xyz:myFirst/child::text())') != 0]">
//Do something First Here
</when>
<when expression="#[xpath('fn:count(//soapenv:Envelope/soapenv:Body/xyz:mySecond/child::text())') != 0]">
//Do something Second Here
</when>
<otherwise>
//Didn't match any!
</otherwise>
</choice>
但是“myFirst”从未被识别,因为它是空的。我尝试了在这个位置提到的内容Using XPath to Check if Soap Envelope Contains Child Node,但无济于事。我目前的尝试基于How to tell using XPath if an element is present and non empty?。
思想?
答案 0 :(得分:1)
在您XPath
上进行测试的child text node
中,如果样本有效负载中有一个空节点,那么它就永远不会出现在首选元素上。如果意图是即使节点为空也要执行任务,请执行以下操作:
<choice>
<when expression="#[xpath('fn:count(//soapenv:Envelope/soapenv:Body/xyz:myFirst)') != 0]">
//Do something First Here
</when>
<when expression="#[xpath('fn:count(//soapenv:Envelope/soapenv:Body/xyz:mySecond') != 0]">
//Do something Second Here
</when>
<otherwise>
//Didn't match any!
</otherwise>
</choice>