如何访问主体和/或避免mule数据编织中xml节点中NULL值的错误。处理Dataweave中的NULL xml节点
考虑这是我的节点:
<catalog>
<product product-id="D158413" mode="delete"/>
<product product-id="556204380">
<ean>5014414203648</ean>
<display-name>Double duvet cover</display-name>
<long-description>Line</long-description>
<online-flag>true</online-flag>
<available-flag>true</available-flag>
<searchable-flag>true</searchable-flag>
<tax-class-id>default</tax-class-id>
<brand>Linea</brand>
<manufacturer-name>Linea</manufacturer-name>
<custom-attributes>
<custom-attribute attribute-id="Care Instructions">Machine</custom-attribute>
<custom-attribute attribute-id="Colour">Pink</custom-attribute>
<custom-attribute attribute-id="Finish">Plain</custom-attribute>
<custom-attribute attribute-id="Guarantee">N/A</custom-attribute>
</product>
</catalog>
我Dataweave代码是:
%dw 1.0
%input payload application/xml
%output application/java
---
(payload.catalog.*product default []) map {
CatalogDetails:{
CatalogId:[email protected]
},
ProdDetails:{
product-id:[email protected],
mode:[email protected],
ean:$.ean,
upc:$.upc,
min-order-quantity:$.min-order-quantity,
display-name:$.display-name,
short-description:$.short-description
},
CustValues: { (
($.custom-attributes.*custom-attribute default []) map {
(sellByUnitVal: $) when ([email protected]) == "sellByUnit" ,
(VOLUMEVal: $) when ([email protected]) == "VOLUME",
(UnitMeasureVal: $) when ([email protected]) == "UnitMeasure"
}
) }
}
的第一款产品节点没有收到一个机构。我尝试使用默认[]
,但它不工作。我怎样才能确保它总是收到一个身体?
它不是第三个产品是空的吗?你能告诉我们你用来读取xml节点的代码吗? – StillLearnin
我分享了我的示例代码..请看看 –