如何丢弃 Dataweave 2 中的空 XML 标签
How to discard empty XML Tag in Dataweave 2
我有以下 Dataweave 2 片段。输出为 application/xml.
ns0#Accounting_Worktag_Reference: if (payload01.PROJECT != null and payload01.PROJECT != ""){
ns0#ID @(ns0#"type": "Project_ID"): payload01.PROJECT} else null
当Project_ID为null
时,我得到一个空元素输出如下
<ns0:Accounting_Worktag_Reference/>
我想跳过这个空元素。我尝试了文档中提到的指令 skipNullOn="everywhere" 但仍然输出空元素。当 Project_ID 为空时,有没有其他方法可以跳过空元素。
基本上,您需要使用此 if
语法,如本例所示:https://docs.mulesoft.com/mule-runtime/4.3/dataweave-cookbook-output-a-field-when-present
在您的情况下,它将如下所示:
%dw 2.0
output application/xml
ns ns0 http://some
---
{ns0#root:
(ns0#Accounting_Worktag_Reference: { ns0#ID @(ns0#"type": "Project_ID"): payload.PROJECT} )
if (payload.PROJECT != null and payload.PROJECT != "")
}
我有以下 Dataweave 2 片段。输出为 application/xml.
ns0#Accounting_Worktag_Reference: if (payload01.PROJECT != null and payload01.PROJECT != ""){
ns0#ID @(ns0#"type": "Project_ID"): payload01.PROJECT} else null
当Project_ID为null
时,我得到一个空元素输出如下<ns0:Accounting_Worktag_Reference/>
我想跳过这个空元素。我尝试了文档中提到的指令 skipNullOn="everywhere" 但仍然输出空元素。当 Project_ID 为空时,有没有其他方法可以跳过空元素。
基本上,您需要使用此 if
语法,如本例所示:https://docs.mulesoft.com/mule-runtime/4.3/dataweave-cookbook-output-a-field-when-present
在您的情况下,它将如下所示:
%dw 2.0
output application/xml
ns ns0 http://some
---
{ns0#root:
(ns0#Accounting_Worktag_Reference: { ns0#ID @(ns0#"type": "Project_ID"): payload.PROJECT} )
if (payload.PROJECT != null and payload.PROJECT != "")
}