首页 > 解决方案 > 为什么 Multipart/form-data 删除 Nill 以响应 Mule Dataweave

问题描述

<Date xsi:nil="true"/>请在我的请求穿过数据编织时找到带有标签的请求,Multipart/form-data它正在删除xsi:nil="true我的场景中不期望的部分。我希望那是一样的。

此外,它正在删除不是预期情况的命名空间。如果我尝试ns xsi http://www.w3.org/2001/XMLSchema-instance在第一个 dataweave 中声明。在响应根元素中,它带有前缀xsi:Locations。我正在为此苦苦挣扎。

想要如下所述的响应,无论输入相同,都应该不改变。

使用writeNilOnNull=true将 nill 放在我不想要的所有字段上,只想要日期。

任何人都可以帮助解决这个问题。谢谢你。

输入:

<Locations xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Location>
    <Id>2</Id>
    <CarId>78</CarId>
    <Packages>1</Packages>
    <Date xsi:nil="true"/>
   </Location>
</Locations>

预期反应:

 <Locations xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Location>
    <Id>2</Id>
    <CarId>78</CarId>
     <Packages/>
    <Date xsi:nil="true"/>
   </Location>
</Locations>

流动:

        <flow name="question" doc:id="8c836a85-9d0a-47a8-8e5a-f670b16f91eb" >
        <http:listener doc:name="Listener" doc:id="52ffdb08-9587-4cb2-8232-9467e85ea0dc" config-ref="HTTP_Listener_config" path="/question"/>
        <ee:transform doc:name="Transform Message" doc:id="da995adf-196b-4c7b-a265-874f059ed1bb" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/xml 
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <ee:transform doc:name="Transform Message" doc:id="75e5d876-855e-4d38-8468-3484c859f36e" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output multipart/form-data 
---
{
  "parts": {
    "file": {
      "headers": {
        "Content-Disposition": {
          "name": "file",
          "filename": "",
          "subtype": "form-data"
        },
        "Content-Type": "application/xml"
      },
      "content": payload
    }
  }
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
</mule>

标签: muledataweavemulesoftmule4

解决方案


在您的转换中添加writeNilOnNull=true。像这样

%dw 2.0
var x=read('<Locations xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Location>
    <Id>2</Id>
    <CarId>78</CarId>
    <Packages>1</Packages>
    <Date xsi:nil="true"/>
   </Location>
</Locations>','application/xml')
output application/xml writeNilOnNull=true
---
x

在此处输入图像描述


推荐阅读