Mule - 将XML转换为SOAP消息

时间:2016-02-08 19:17:50

标签: xml xslt soap mule transform

我收到JSON的{​​{1}}消息,如下所示:

mule flow

然后我使用带有mule的{ "book": { "author": "Gambardella, Matthew", "title": "XML Developer's Guide", "genre": "Computer", "price": "44.95", "publish_date": "2000-10-01", "description": "An in-depth look XML" } } 并返回:

JSON to XML transformer

这是我的实际骡子流:

<book > <author>Gambardella, Matthew</author> <title>XML Developer's Guide</title> <genre>Computer</genre> <price>44.95</price> <publish_date>2000-10-01</publish_date> <description>An in-depth look XML</description> </book> - &gt; HTTP - &gt; JSON To XML - &gt; Logger

我希望转换WS Consumer消息,添加 URI 前缀

为什么我需要Prefix和SOAP消息?我需要它发送到Web服务并发送如下:

XML to SOAP

我尝试添加... <pref:author>Gambardella, Matthew</pref:author> ... ,但在使用XSLT component:(十六进制代码)时会返回错误。

我想使用&#x3a;但它只适用于Dataweave (Mapper) component

这是我想要的结果:

Mule Enterprise Edition

进行转型的最佳方式是什么?

1 个答案:

答案 0 :(得分:3)

以下样式表:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:pref="URI_SOAP_WS">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="/">
    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope/" xmlns:pref="URI_SOAP_WS">
        <soap:Body>
            <xsl:apply-templates/>
        </soap:Body>
    </soap:Envelope>
</xsl:template>

<xsl:template match="*">
    <xsl:element name="pref:{local-name()}">
        <xsl:apply-templates/>
    </xsl:element>
</xsl:template>

</xsl:stylesheet>

应用于您的XML示例时,将返回:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope/" xmlns:pref="URI_SOAP_WS">
   <soap:Body>
      <pref:book>
         <pref:author>Gambardella, Matthew</pref:author>
         <pref:title>XML Developer's Guide</pref:title>
         <pref:genre>Computer</pref:genre>
         <pref:price>44.95</pref:price>
         <pref:publish_date>2000-10-01</pref:publish_date>
         <pref:description>An in-depth look XML</pref:description>
      </pref:book>
   </soap:Body>
</soap:Envelope>