你可以尝试以下配置:
<enricher doc:name="Message Enricher">
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/java
%var evaluation = "ABC"
%var substitution = "BC"
%function substitute(serverVal)(
serverVal when serverVal != evaluation otherwise substitution
)
---
[email protected] mapObject {
($$): substitute($)
}
]]></dw:set-payload>
</dw:transform-message>
<enrich source="#[payload.Server]" target="#[variable:param1]"/>
<enrich source="#[payload.Server2]" target="#[variable:param2]"/>
</enricher>
不管如何在XML源很多属性,你只需要添加相应的富集元素。
例如,你有一个新的XML源:<Interface Server="ABC" Server2="DEF" Server3="ABC"/>
然后你只需要添加:<enrich source="#[payload.Server3]" target="#[variable:param3]"/>
设置新的变量。
备注:DataWeave是EE功能之一。对于CE,您可以将其替换为其他变压器,例如:Groovy。在下面的例子中,有效载荷是以String的形式出现的。使用byte-array-to-string-transformer
将原始应用程序/ xml格式转换为字符串。
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy"><![CDATA[def attributeMap = new XmlSlurper().parseText(payload).attributes()
attributeMap.each() {
it.value = it.value == "ABC" ? "BC" : it.value
}
payload = attributeMap]]></scripting:script>
</scripting:component>
不错的办法,我给一个去 – elwis
嗯,我得到的SAXParser例外情况是,只有DataWeave - 因为我跑CE? – elwis
* DataWeave *是** EE **功能之一。我更新了使用Groovy作为替换的答案。 –