在MuleSoft的DataWeave中循环

时间:2016-05-03 07:04:33

标签: mule dataweave

我有一个要求,我需要提取 LoadReferenceNumber 并分配给 LoadReferenceNumberType MB <时在数据编织内启动的变量/ strong>在mule中,下面是xml

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<CIS>
<LoadReferenceNumberList>
		<LoadReferenceNumberType>MB</LoadReferenceNumberType>
		<LoadReferenceNumber>8070296</LoadReferenceNumber>
	</LoadReferenceNumberList>
	<LoadReferenceNumberList>
		<LoadReferenceNumberType>ACT_SP_DATE</LoadReferenceNumberType>
		<LoadReferenceNumber>20160404T14:12:00</LoadReferenceNumber>
	</LoadReferenceNumberList>
	<LoadReferenceNumberList>
		<LoadReferenceNumberType>SP_DATE</LoadReferenceNumberType>
		<LoadReferenceNumber>20170404T14:12:00</LoadReferenceNumber>
	</LoadReferenceNumberList>
  </CIS>

2 个答案:

答案 0 :(得分:0)

下面的示例是一个dataweave组件,它从LoadReferenceNumberList中提取LoadReferenceNumber,其中LoadReferenceNumberType =='MB':

<dw:set-variable variableName="LoadReferenceNumber"><![CDATA[%dw 1.0
%output application/java
---
value: ((payload.CIS.*LoadReferenceNumberList filter $.LoadReferenceNumberType == 'MB')[0].LoadReferenceNumber) default null]]></dw:set-variable>
        </dw:transform-message>

结果是LinkedHashMap,下面的示例是logger,它记录了LoadReferenceNumber:

<logger message="#[flowVars.LoadReferenceNumber.value]" level="INFO"
                doc:name="Logger" />

希望这会有所帮助:)

答案 1 :(得分:0)

你使用那个数据编织

%dw 1.0
%output application/java
---
value: ((payload.CIS.*LoadReferenceNumberList filter $.LoadReferenceNumberType == 'MB')[0].LoadReferenceNumber) default null