删除XML头声明,并在DataWeave 2.0中提供不带前缀的XML名称空间
我希望XML的外观如下所示,没有标题:删除XML头声明,并在DataWeave 2.0中提供不带前缀的XML名称空间,xml,namespaces,dataweave,mulesoft,Xml,Namespaces,Dataweave,Mulesoft,我希望XML的外观如下所示,没有标题: <LicenseCodeRequest xmlns="http://www.gilmore.ca/services/eVantageBookLicense" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <ClientID>XXX</ClientID> <PartNumber>1000-VS1</PartNumb
<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>
如果我在LicenseCodeRequest:
前面添加gilmore
,它会将输出更改为:
gilmore:LicenseCodeRequest xmlns="http://www.gilmore.ca/services/eVantageBookLicense"
但是:
gilmore:LicenseCodeRequest…
我只需要它是LicenseCodeRequest…
和非常感谢。您可以在输出标题(文档)中使用
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属性的实际示例。很抱歉,需要澄清的是,转换创建的标题是:这就是我想要消除的。谢谢Jerney。这太棒了。一位同事确实告诉过我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: ...
...
}
}