如何在 mule 4 中用 0 替换“#N/A”
How to replace "#N/A" with 0 in mule 4
我正在尝试将 xml 的所有属性中的 "#N/A" 值替换为 0。
输入xml:
<DTOSteps>
<DTOStep Order="1" Name="Rated Premium" Operation="=" Factor="#N/A" Value="#N/A">
<DTOSteps>
<DTOStep Order="1" Name="Property Damage" Operation="=" Factor="#N/A" Value="#N/A">
<DTOSteps>
<DTOStep Order="1" Name="AOI" Operation="=" Factor="#N/A" Value="#N/A"/>
<DTOStep Order="2" Name="Base" Operation="-" Factor="#N/A" Value="#N/A"/>
<DTOStep Order="3" Name="Deductible" Operation="-" Factor="#N/A" Value="#N/A"/>
</DTOSteps>
</DTOStep>
<DTOStep Order="2" Name="Business Income And Extra Expense" Operation="+" Factor="#N/A" Value="#N/A">
<DTOSteps>
<DTOStep Order="4" Name="AOI" Operation="=" Factor="#N/A" Value="#N/A"/>
<DTOStep Order="5" Name="Base" Operation="-" Factor="#N/A" Value="#N/A"/>
<DTOStep Order="6" Name="Deductible" Operation="-" Factor="#N/A" Value="#N/A"/>
</DTOSteps>
</DTOStep>
</DTOSteps>
</DTOStep>
<DTOStep Order="2" Name="Term Factor" Operation="X" Factor="#N/A" Value="#N/A"/>
</DTOSteps>
预期输出:https://github.com/Manikandan99/Map_request/blob/main/Response_dwl.xml
关于如何在 dataweave 2.0 中替换有什么想法吗?
使用下面给出的脚本。
%dw 2.0
output application/xml
var updateAttribute = (element) ->
element mapObject (value, key) -> {
(key) @(
(
if (key.@?)
(key.@ mapObject ((attr_value, attr_key) -> {
(attr_key): if (attr_value == "#N/A") "0" else attr_value
}))
else {}
)
) :
if (value is Object)
updateAttribute(value)
else value
}
---
updateAttribute(payload)
我正在尝试将 xml 的所有属性中的 "#N/A" 值替换为 0。
输入xml:
<DTOSteps>
<DTOStep Order="1" Name="Rated Premium" Operation="=" Factor="#N/A" Value="#N/A">
<DTOSteps>
<DTOStep Order="1" Name="Property Damage" Operation="=" Factor="#N/A" Value="#N/A">
<DTOSteps>
<DTOStep Order="1" Name="AOI" Operation="=" Factor="#N/A" Value="#N/A"/>
<DTOStep Order="2" Name="Base" Operation="-" Factor="#N/A" Value="#N/A"/>
<DTOStep Order="3" Name="Deductible" Operation="-" Factor="#N/A" Value="#N/A"/>
</DTOSteps>
</DTOStep>
<DTOStep Order="2" Name="Business Income And Extra Expense" Operation="+" Factor="#N/A" Value="#N/A">
<DTOSteps>
<DTOStep Order="4" Name="AOI" Operation="=" Factor="#N/A" Value="#N/A"/>
<DTOStep Order="5" Name="Base" Operation="-" Factor="#N/A" Value="#N/A"/>
<DTOStep Order="6" Name="Deductible" Operation="-" Factor="#N/A" Value="#N/A"/>
</DTOSteps>
</DTOStep>
</DTOSteps>
</DTOStep>
<DTOStep Order="2" Name="Term Factor" Operation="X" Factor="#N/A" Value="#N/A"/>
</DTOSteps>
预期输出:https://github.com/Manikandan99/Map_request/blob/main/Response_dwl.xml
关于如何在 dataweave 2.0 中替换有什么想法吗?
使用下面给出的脚本。
%dw 2.0
output application/xml
var updateAttribute = (element) ->
element mapObject (value, key) -> {
(key) @(
(
if (key.@?)
(key.@ mapObject ((attr_value, attr_key) -> {
(attr_key): if (attr_value == "#N/A") "0" else attr_value
}))
else {}
)
) :
if (value is Object)
updateAttribute(value)
else value
}
---
updateAttribute(payload)