Question

I'm new to Mule, please guide me how to insert new tag inside the XML structure using Mule Expression Language (MEL).Need to insert B tag in the below XML structure

<Test>
<A>table 1</A>
<C>table 3</C>
</Test> 

Thanks in Advance.

Was it helpful?

Solution

My dom4j fu is limited but here is what I came up with:

<mulexml:xml-to-dom-transformer returnClass="org.dom4j.Document" />

<expression-component><![CDATA[
  bNode = message.payload.rootElement.addElement('B');
  bNode.text = 'table 2';
  message.payload.rootElement.elements().add(1, bNode.detach());
]]></expression-component>

<mulexml:dom-to-xml-transformer />

This works fine with Mule 3.4.0.

OTHER TIPS

Use a Data Weave component as below:

%dw 1.0
%output application/xml
%var myValue='MyValue'
%var B=''
---

myoutput:{
    data: payload.Test ++ B:myValue

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top