无法使用 mule 变量从 xpath-extract 中提取值
can't extract value from xpath-extract using mule variables
我有一组 LocationProperties 变量作为其 Location-465697646-800339871 值。基于变量的值,我想 select 有效载荷中的一个节点。
骡子 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)
Mule 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 returns 3,
xvalue2 returns 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 提取器之后使用下面的 dataweave 代码
%dw 2.0
output application/json
---
(vars.xvalue1 default [] ++ vars.xvalue2 default []) joinBy ","
o/p 将是:- "3,1"
我有一组 LocationProperties 变量作为其 Location-465697646-800339871 值。基于变量的值,我想 select 有效载荷中的一个节点。
骡子 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)
Mule 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 returns 3,
xvalue2 returns 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 提取器之后使用下面的 dataweave 代码
%dw 2.0
output application/json
---
(vars.xvalue1 default [] ++ vars.xvalue2 default []) joinBy ","
o/p 将是:- "3,1"