如何从 xml 负载中删除命名空间
How to remove namespaces from xml payload
我想从我的 XML 输入中删除所有命名空间。
输入负载
<?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>
要求输出:
<?xml version='1.0' encoding='UTF-8'?>
<Envelope >
<Header/>
<Body>
<GetVehDetails/>
</Body>
</Envelope>
基于之前的回答此函数删除所有命名空间而无需指定一个。
%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)
我想从我的 XML 输入中删除所有命名空间。
输入负载
<?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>
要求输出:
<?xml version='1.0' encoding='UTF-8'?>
<Envelope >
<Header/>
<Body>
<GetVehDetails/>
</Body>
</Envelope>
基于之前的回答
%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)