如何在 Mulesoft 中嵌入 CDATA

How to embed CDATA in Mulesoft

我正在尝试在 Mulesoft 流中嵌入文字 CDATA 值,但不知道该怎么做。

我想要的输出(在 HTTP 请求正文中)是:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <query xmlns="http://autotask.net/ATWS/v1_5/">
            <sXML>
                <![CDATA[<queryxml><entity>ticket</entity><query><condition><field>id<expression op="equals">12345</expression></field></condition></query></queryxml>]]>
            </sXML>
        </query>
    </soap:Body>
</soap:Envelope>

我的 Dataweave 转换如下所示:

%dw 1.0
%output application/xml
%namespace soap http://schemas.xmlsoap.org/soap/envelope
---
{
    soap#Envelope @(version: "1.0") : {                  
        soap#Header: {},
        soap#Body: {
            query: {                
                sXML: "<queryxml><entity>ticket</entity><query><condition><field>id<expression op=\"equals\">12345</expression></field></condition></query></queryxml>"                     
            }
        }
    }
}

但是当我将此请求发送到 requestb.in(检查内容)时,我可以看到它是这样通过的(关注 sXML 实体):

<?xml version='1.0' encoding='UTF-8'?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope" version="1.0">
  <soap:Header/>
  <soap:Body>
    <query>     
      <sXML>&lt;queryxml>&lt;entity>ticket&lt;/entity>&lt;query>&lt;condition>&lt;field>id&lt;expression op="equals">12345&lt;/expression>&lt;/field>&lt;/condition>&lt;/query>&lt;/queryxml></sXML>
    </query>
  </soap:Body>
</soap:Envelope>

我如何通过 dataweave/MEL 获取其中的文字 CDATA 值?

谢谢。

我会尝试:

sXML: "<queryxml> .... </queryxml>" as :cdata

有关详细信息,请参阅 https://docs.mulesoft.com/mule-user-guide/v/3.8/dataweave-formats#custom-types-2

handleInteractiveOrder: write(vars.subm.soap#Envelope.soap#Body.cp#handleInteractiveOrder,"application/xml") as CData

在 mule 4 中我们可以这样做。我将 XML 保存在 subm 变量中。