如何访问主体和/或避免 mule 数据编织中 xml 节点中的 NULL 值错误。
考虑这是我的节点:
<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:payload.catalog.@catalog-id
},
ProdDetails:{
product-id:$.@product-id,
mode:$.@mode,
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 ($.@attribute-id) == "sellByUnit" ,
(VOLUMEVal: $) when ($.@attribute-id) == "VOLUME",
(UnitMeasureVal: $) when ($.@attribute-id) == "UnitMeasure"
}
) }
}
第一个 Product 节点没有收到正文。我尝试使用默认值[]
,但它不起作用。我怎样才能确保它总是收到一个身体?