为什么Multipartform-data在响应Mule Dataweave时删除Nill?

问题描述 投票:0回答:1

请看我的要求,标签是 <Date xsi:nil="true"/> 过了 Multipart/form-data 数据编织,它是去除 xsi:nil="true 部分,这在我的方案中是没有预料到的。我希望这也是出来的一样。

另外,它还删除了命名空间,这不是预期的情况。如果我尝试声明 ns xsi http://www.w3.org/2001/XMLSchema-instance 在第一个数据编织中。在响应根元素中,它的前缀是 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>
mule dataweave mulesoft mule4
1个回答
0
投票

添加 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

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.