【问题标题】:Mulesoft XML dataweave set namespace for attributesMulesoft XML dataweave 为属性设置命名空间
【发布时间】:2020-01-09 09:08:48
【问题描述】:

我正在尝试形成一个具有某些属性的 xml 请求。这些属性也有一些命名空间。有人可以帮助我使用正确的语法来形成正确的 xml 请求。

例如

     Sample xml

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:ns1="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:ns2="http://www.w3.org/2001/XMLSchema"
     <soapenv:Header/>
        <soapenv:Body>
        <Request>
        <soapenv:age ns1:type="ns2:string">1234</soapenv:age>
        </Request>
    </soapenv:Body>
    </soapenv:Envelope> 


    dataweave
    %dw 1.0
    %output application/xml
    {
     ns1#age @(ns1#type: "ns2#string"): "1234"
     }

【问题讨论】:

    标签: xml mule transform mule-studio dataweave


    【解决方案1】:
    %dw 1.0
    %output application/xml encoding="utf-8"
    %namespace soapenv http://schemas.xmlsoap.org/soap/envelope/
    %namespace ns1 http://www.w3.org/2001/XMLSchema-instance
    %namespace ns2 http://www.w3.org/2001/XMLSchema
    ---
    soapenv#Envelope: {
      soapenv#Header  : {
          soapenv#Body: {
            Request: {
              soapenv#age @(ns1#type: "ns2#string"): "1234"
            }
        }
      }
    }
    

    输出:

    <?xml version='1.0' encoding='utf-8'?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
      <soapenv:Header>
        <soapenv:Body>
          <Request>
            <soapenv:age xmlns:ns1="http://www.w3.org/2001/XMLSchema-instance" ns1:type="ns2#string">1234</soapenv:age>
          </Request>
        </soapenv:Body>
      </soapenv:Header>
    </soapenv:Envelope>
    

    请注意,转换不使用 ns2,因此它不会在输出中发出。如果您需要它出现,您需要将虚拟属性添加到以 ns2 作为命名空间的某个元素(例如 @(ns2#dummy:'')

    【讨论】:

    • 谢谢,但我还需要为“ns2#string”传递 namsespace,否则无法将错误字符串识别为任何模式类型。
    • 然后你需要添加一个带有 ns2 命名空间的虚拟属性,正如我所提到的。你试过了吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多