I am trying to create below XML in mulesoft 4.4.0 using dataweave script.
<?xml version='1.0' encoding='UTF-8'?>
<batch>
<nsA:parent xmlns:nsA="http://www.testA.com/core" xmlns:nsB="http://www.testB.com/core">
<nsB:child >ChildNodeValue</nsB:child>
</nsA:parent>
</batch>
Dataweave scripts I tried are :
1st Try:
%dw 2.0
output application/xml
ns nsA http://www.testA.com/core
ns nsB http://www.testB.com/core
---
batch: {
(payload map ((item, index) -> {
nsA#parent:{
nsB#child:"ChildNodeValue"
}
})
)}
-------------------------------------
Output:
<?xml version='1.0' encoding='UTF-8'?>
<batch>
<nsA:parent xmlns:nsA="http://www.testA.com/core">
<nsB:child xmlns:nsB="http://www.testB.com/core">ChildNodeValue</nsB:child>
</nsA:parent>
</batch>
2nd try: : Using writeDeclaredNamespaces="All"
%dw 2.0
output application/xml writeDeclaredNamespaces="All"
ns nsA http://www.testA.com/core
ns nsB http://www.testB.com/core
---
batch: {
(payload map ((item, index) -> {
nsA#parent:{
nsB#child:"ChildNodeValue"
}
})
)}
---------------------------
Output:
<?xml version='1.0' encoding='UTF-8'?>
<batch xmlns:nsA="http://www.testA.com/core" xmlns:nsB="http://www.testB.com/core">
<nsA:parent>
<nsB:child>ChildNodeValue</nsB:child>
</nsA:parent>
</batch>
How can I move the namespaces to a specific parent node (not the root node) in XML output?
Thank you