Ask Your Question

Revision history [back]

click to hide/show revision 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:

  1. Use the XPath expression in MEL to select the contents of the element you want to remove.

#[xpath('//elementName/*')]

This expression selects all the child elements of the element named "elementName."

  1. Use the "groovy:XmlUtil.serialize" function to convert the result of the XPath expression back into XML with just the namespaces and attributes.

#[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.