如何在Mulesoft中嵌入CDATA

时间:2016-10-06 18:24:57

标签: mule mule-el dataweave

我正在尝试在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值?

谢谢。

2 个答案:

答案 0 :(得分:2)

我会尝试:

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

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

答案 1 :(得分:0)

  

handleInteractiveOrder:   写(vars.subm.soap#Envelope.soap#Body.cp#handleInteractiveOrder,“应用程序/ xml”)   作为CData

在m子4中,我们可以这样做。我将XML保留在subm变量中。