0

我希望 XML 看起来像下面这样,没有标题:

<LicenseCodeRequest xmlns="http://www.gilmore.ca/services/eVantageBookLicense" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">    
    <ClientID>XXX</ClientID>    
    <PartNumber>1000-VS1</PartNumber>    
    <Qty>2</Qty>    
    <CustomerOrderNumber>56789</CustomerOrderNumber>    
    <BillingReferenceID>1234</BillingReferenceID>    
    <SoldToCode>XX-XXX</SoldToCode>    
    <Students>
      <Student>
         <StudentID>1</StudentID>
         <StudentFirstName>Some</StudentFirstName>
         <StudentLastName>One</StudentLastName>
         <StudentEmail>someone@exampe.com</StudentEmail>
      </Student>
      <Student>
         <StudentID>2</StudentID>
         <StudentFirstName>Another</StudentFirstName>
         <StudentLastName>One</StudentLastName>
         <StudentEmail>anotherone@exampe.com</StudentEmail>
      </Student>    
   </Students>    
   <SendStudentEmail>false</SendStudentEmail>    
   <ContactFirstName>me</ContactFirstName>    
   <ContactLastName>myself</ContactLastName>    
   <ContactEmail>me.myself@example.com</ContactEmail>    
   <SendContactEmail>true</SendContactEmail>    
   <ShipAddress1>123</ShipAddress1>    
   <ShipAddress2></ShipAddress2>    
   <ShipCity>someplace</ShipCity>    
   <ShipState>NM</ShipState>    
   <ShipCountry>US</ShipCountry>    
   <ShipZipcode>54481</ShipZipcode>    
   <Language>en</Language>    
   <AssignmentApplication>false</AssignmentApplication> 
</LicenseCodeRequest>

然而,当我预览我的 Transform 消息的输出时,我看到以下内容:

<?xml version='1.0' encoding='UTF-8'?>

这将导致提交到供应商的 API 失败。

问题1:我如何摆脱这个标题?

问题 2:如何将两个命名空间添加到 XML 行。我的数据编织中有以下内容:

%dw 2.0
output application/xml  
ns gilmore http://www.gilmore.ca/services/eVantageBookLicense 
ns w3i http://www.w3.org/2001/XMLSchema-instance
---
LicenseCodeRequest: {   
  ClientID: XXX,   
  PartNumber: "1000-VS1",   
  Qty: 1,   
  CustomerOrderNumber: 56789,   
  BillingReferenceID: 1234,   
  SoldToCode: "XX-XXXX",   
  Students: {       
    Student: {
      StudentID: 1,
      StudentFirstName: "Some",
      StudentLastName: "One",
      StudentEmail:payload.email,       
    }   
  },   
  SendStudentEmail: false,   
  ContactFirstName: "me",   
  ContactLastName: "myself",   
  ContactEmail: "me.myself@example.com",   
  SendContactEmai: true,   
  ShipAddress1: 123,   
  ShipAddress2: "",   
  ShipCity: "someplace",   
  ShipState: "NM",   
  ShipCountry: "US",   
  ShipZipcode: 54481,   
  Language: "en",   
  AssignmentApplication: false 
}

如果我gilmore#在前面添加LicenseCodeRequest:它会将输出更改为:

gilmore:LicenseCodeRequest xmlns="http://www.gilmore.ca/services/eVantageBookLicense"

但:

  1. 我不希望它成为gilmore:LicenseCodeRequest... 我只需要它LicenseCodeRequest...成为
  2. 我需要将第二个命名空间放入同一个标签中。

我怎么做?

非常感谢您提前。

4

1 回答 1

1

您可以writeDeclaration=false在输出标题中使用(此处的文档)

例子:

%dw 2.0
output application/xml writeDeclaration=false
---
[insert transformation code here]

我认为您将很难使用名称空间,但是您可以尝试这种技巧并使用属性来代替您要完成的工作。我只是建议使用大量评论,因为您所做的是非标准行为:

%dw 2.0
output application/xml writeDeclaration=false

var xmlns  = "http://www.gilmore.ca/services/eVantageBookLicense"
var xmlnsi = "http://www.w3.org/2001/XMLSchema-instance"
---
{
  LicenseCodeRequest @("xmlns": xmlns, "xmlns:i": xmlnsi): {
    ClientId: ...
    ...
  }
}

您可以在此处找到更多在 DataWeave 2.0 中使用 XML 属性的实际示例。

于 2019-03-19T14:25:45.983 回答