Mule - 将 XML 转换为 SOAP 消息

Mule - Transform XML to SOAP message

我收到一条 JSON 消息给我的 mule flow 是这样的:

{
  "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 和骡子 returns:

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

这是我的实际 mule 流:

HTTP --> JSON To XML --> Logger --> WS Consumer

我想转换 XML to SOAP 消息,添加 URIPrefix.

为什么我需要前缀和 SOAP 消息?我需要它发送到网络服务并发送如下:

...
    <pref:author>Gambardella, Matthew</pref:author>
...

我试图添加一个 XSLT component,但是当我使用 :&#x3a;(十六进制代码)时 return 我出错了。

我想使用 Dataweave (Mapper) component 但它只适用于 Mule Enterprise Edition

这是我想要的结果:

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

进行该转换的最佳方法是什么?

以下样式表:

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 示例时,将 return:

<?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>