1 | initial version |
To remove XML tags from the payload in Mule 3.9 while retaining the namespaces and attributes, you can use the MEL (Mule Expression Language) expressions with the transformers.
Here is an example of how to do it:
#[xpath('//elementName/*')]
This expression selects all the child elements of the element named "elementName."
#[groovy:com.sun.org.apache.xml.internal.serialize.XmlSerializer.serialize(muleContext.transformMessage(payload, 'xpath://elementName/*'))]
The "transformMessage" function takes the generated XML as input and removes any unnecessary tags while retaining the namespaces and attributes.
Full code example:
<flow name="removeXmlTagsFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<set-payload value="#[xpath('//elementName/*')]" doc:name="Set Payload"/>
<set-payload value="#[groovy:com.sun.org.apache.xml.internal.serialize.XmlSerializer.serialize(muleContext.transformMessage(payload, 'xpath://elementName/*'))]" doc:name="Set Payload"/>
<!-- Other code goes here -->
</flow>
This code will remove the tags from the "elementName" element, keeping the namespaces and attributes intact.