3

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.

David Dossot
  • 33,403
  • 4
  • 38
  • 72
star
  • 1,493
  • 1
  • 28
  • 61

2 Answers2

6

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.

David Dossot
  • 33,403
  • 4
  • 38
  • 72
  • Thanks David.It is workig fine for me.Kindly help me in understanding which script is used here in manipulating rootElement,addElement(),elements().add().Also referred XML DOM in W3schools,but unable to correlate both.Kindly help. – star Aug 06 '13 at 10:41
3

Use a Data Weave component as below:

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

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

}
Sudha Ch
  • 127
  • 1
  • 7