我有一个集合LocationProperties变量作为其Location-465697646-800339871值。根据变量的值,我想在有效负载中选择一个节点。
骡子3:
xpath3('//DTOLocation[@id='' + flowVars.LocationProperties.LocationRef + ''][1]/DTOLocationDetail[@DetailTypeCd='CommercialPropertyLocationDetail'][1]/@ProtectionClassCd',flowVars.domPayload)
xpath3('//DTOLocation[@id=' + flowVars.LocationProperties.LocationRef + '][1]/@LocationCounterNumber',flowVars.domPayload)
骡子4流量:
<flow name="var_xpath_testFlow" doc:id="406270fb-17e7-48e9-a33a-f7a0197f8e05" >
<http:listener doc:name="Listener" doc:id="662f2277-859f-4516-974b-de7cceeb5b40" config-ref="HTTP_Listener_config" path="/vartest"/>
<set-variable value="#[payload]" doc:name="Set domPayload" doc:id="2495ac98-b976-41e0-9dcf-398574e54ffa" variableName="domPayload"/>
<set-variable value="Location-465697646-800339871" doc:name="Set Variable" doc:id="12370458-bb32-4709-b509-acc1e5f50b94" variableName="LocationProperties"/>
<xml-module:xpath-extract xpath="#["/DTOApplication/DTOLocation[@id='" ++ vars.LocationProperties ++ "'][1]"/DTOLocationDetail[@DetailTypeCd='CommercialPropertyLocationDetail'][1]/@ProtectionClassCd]" target="xvalue1" config-ref="XML_Config"/>
<xml-module:xpath-extract xpath="#["/DTOApplication/DTOLocation[@id='" ++ vars.LocationProperties ++ "'][1]"/@LocationCounterNumber]" config-ref="XML_Config" target="xvalue2"/>
<logger level="INFO" doc:name="Logger" doc:id="f495b0bf-f8cb-43be-b4d9-d069758e4028" message="#[vars.xvalue]"/>
</flow>
输入有效载荷:https://github.com/Manikandan99/rate-dtostep/blob/master/request.xml
预期输出为变量:
xvalue1返回3,
xvalue2返回1。
如果我直接在xpath中给出值,那就是工作。
当我试图在xpath中使用变量时,它会抛出如下错误:https://github.com/Manikandan99/rate-dtostep/blob/master/xapth_error.txt
如何在XPath Mule 4中使用变量提取值?
错误是因为您没有在XPath 的表达式中正确添加双代码
我已经做了一些更正,如下
<flow name="var_xpath_testFlow" doc:id="406270fb-17e7-48e9-a33a-f7a0197f8e05" >
<http:listener doc:name="Listener" doc:id="662f2277-859f-4516-974b-de7cceeb5b40" config-ref="HTTP_Listener_config" path="/vartest"/>
<set-variable value="#[payload]" doc:name="Set domPayload" doc:id="2495ac98-b976-41e0-9dcf-398574e54ffa" variableName="domPayload"/>
<set-variable value="Location-465697646-800339871" doc:name="Set Variable" doc:id="12370458-bb32-4709-b509-acc1e5f50b94" variableName="LocationProperties"/>
<xml-module:xpath-extract doc:name="Xpath extract" doc:id="4a8ce1ed-3c1c-48f7-95dd-664654c6a66b" xpath="#["/DTOApplication/DTOLocation[@id='" ++ vars.LocationProperties ++ "'][1]/DTOLocationDetail[@DetailTypeCd='CommercialPropertyLocationDetail'][1]/@ProtectionClassCd"]"/>
<xml-module:xpath-extract doc:name="Xpath extract" doc:id="6287299e-aae5-411b-b6d5-936e6c6be5fb" xpath="#["/DTOApplication/DTOLocation[@id='" ++ vars.LocationProperties ++ "'][1]/@LocationCounterNumber"]"/>
<logger level="INFO" doc:name="Logger" doc:id="f495b0bf-f8cb-43be-b4d9-d069758e4028" message="#[vars.xvalue]"/>
</flow>
这样,您的错误就会得到解决,这在您的问题中已经提到。此外,我不确定为什么你最初在一个名为domPayload的变量中设置有效载荷,因为你没有使用它
根据我们在评论中的讨论,为了您的预期输出,在第二个Xpath提取器之后使用下面的数据编织代码
%dw 2.0
output application/json
---
(vars.xvalue1 default [] ++ vars.xvalue2 default []) joinBy ","
o/p将是:-";3,1〃;