0

I want to remove all the namespaces from my XML input.

Input payload

<?xml version='1.0' encoding='UTF-8'?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://www.mycompany/2015/07">
  <soap:Header/>
  <soap:Body>
    <ns1:GetVehDetails/>
  </soap:Body>
</soap:Envelope>

required output:

<?xml version='1.0' encoding='UTF-8'?>
<Envelope >
  <Header/>
  <Body>
    <GetVehDetails/>
  </Body>
</Envelope>
joono
  • 51
  • 6
  • yes karthik , that helped :) – joono Feb 22 '22 at 12:11
  • Dheeraj, before posting a question, Kindly do some research that is that question already posted by someone or not as same kind of question and solution is here https://stackoverflow.com/questions/71020532/error-trying-to-remove-a-namespace-from-an-xml-in-mule-4 – Anurag Sharma Feb 22 '22 at 13:52
  • 1
    The question is a bit different than the existing one. That one was about removing a single namespace. This one is about removing all namespaces. I'm voting to reopen as this is a valid different question. – aled Feb 22 '22 at 14:01
  • Hi @AnuragSharma, I did search the stack overflow for my requirement " how to remove namespace in dataweave" but did not get many helpful answers. That's why decided to post here. Next time I will be more thorough. – joono Feb 22 '22 at 16:32
  • @aled, yeah agree, this is slightly different from that one already been asked – joono Feb 22 '22 at 16:33

1 Answers1

2

Based on previous answer https://stackoverflow.com/a/71022382/721855 this function removes all namespaces without the need to specify one.

%dw 2.0
output application/xml
fun removeAllNamespace(element) =
  element mapObject (value, key) -> 
             ((key as String)) @((key.@)) : (
                if (value is Object) removeAllNamespace(value)                                  else value
            )
---
removeAllNamespace(payload)
aled
  • 21,330
  • 3
  • 27
  • 34