2

I need to write dataweave code for transforming csv to xml. My output xml should not contain xml declaration('<?xml version='1.0' encoding='UTF-8'?>').

dataweave code:

%dw 1.0
%output application/xml 
---
parent :{
    child1:payload.input1,
    child2:payload.input2
}

expected output:

<parent>
  <child1></child1>
  <child2><child2>
</parent>

present output:

<?xml version='1.0' encoding='UTF-8'?>
 <parent>
      <child1></child1>
      <child2></child2>
 </parent>

please suggest me the directive to be added in headers section. thanks

  • Hi @masetti, the only thing I found is to use XSLT to omit the xml declaration. Please see this link: http://stackoverflow.com/questions/14800746/need-to-remove-xml-version-1-0-encoding-utf-16-from-the-xml – Ralph Rimorin Apr 05 '16 at 15:52

2 Answers2

3

use

%output application/xml writeDeclaration=false
Flo rian
  • 148
  • 10
0

You don't have a way as far as I know to ask dataweave to don't include that declaration, at the end that is a STANDARD xml. Has @ralph-rimorin suggested you could use XSLT but for your case I would do it something a bit dirty but probably faster that is a simple string replace like the following.

<set-payload value="#[message.payloadAs(String).replace('<?xml version="1.0" encoding="UTF-8"?>','')]" doc:name="Remove xml header"/>

Just keep in mind that this will set your XML has string in payload and not as DOM object but this is not a problem in most of mule esb use cases.

Mauro Rocco
  • 4,980
  • 1
  • 26
  • 40