0

我在 Data Weaver 中做 POC。我不确定如何ns0:在整个输出 xml 中声明命名空间。参考链接: https ://developer.mulesoft.com/docs/dataweave (我已经看到使用命名空间 1.4.3 处理输入 xml 的示例,但我正在寻找输出 xml)。

输入 XML:

    <?xml version="1.0" encoding="UTF-8"?>
    <Records>
      <storenumber>12</storenumber>
      <calculated>false</calculated>
      <subTotal>12</subTotal>
   <Records>

预期输出 xml:

<?xml version='1.0' eencoding="UTF-8" standalone="yes"?>
 <ns0:orders 
       xmlns="ns2=urn:test.com:common:v1">
  <ns0:order>
    <ns0:StoreID>12</ns0:StoreID>
    <ns0:Total>false</ns0:Total>
   </ns0:order>
  </ns0:orders>

DataWeaver 转换

%dw 1.0
 %output application/xml
 %var baseurl="ns2=urn:test.com:common:v1"
 ---
 orders @(xmlns:baseurl): {
 order: {
  StoreID: payload.Records.storenumber,
  Total: payload.Records.calculated
  }
}

我相信@(xmlns:baseurl)转型是正确的。有没有其他方法来定义它?

4

1 回答 1

5

命名空间使用指令声明%namespace <prefix> <uri>
您可以指定元素的命名空间<prefix>#<element>

DataWeave 转换

%dw 1.0
%output application/xml
%namespace ns0 urn:test.com:common:v1
---
ns0#orders: {
  ns0#order: {
    ns0#StoreID: payload.Records.storenumber,
    ns0#Total: payload.Records.calculated
  }
}

输出

<?xml version='1.0' encoding='UTF-8'?>
<ns0:orders xmlns:ns0="urn:test.com:common:v1">
  <ns0:order>
    <ns0:StoreID>12</ns0:StoreID>
    <ns0:Total>false</ns0:Total>
  </ns0:order>
</ns0:orders>
于 2015-09-02T01:52:18.617 回答