我有几个 Soap 输入,想根据有效载荷中元素的存在来决定我的 Mule Flow 中的行动方案。
<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"永远不会被识别,因为它是空的。我尝试了在此位置使用 XPath 检查 SOAP 信封是否包含子节点的内容,但无济于事。我目前的尝试是基于如何使用XPath判断元素是否存在且非空?
思潮?
在您的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>