cancel
Showing results for 
Search instead for 
Did you mean: 

content conversion in mapping

hashtag_siva
Explorer
0 Kudos

Hi,

I have a xml document that comes into a mapping as a result of lookup to SAP in XI. The xml structure is

<MT_I_RFC>

<HEADER>1212</HEADER>

<MESSAGE>TEST MESSAGE/DO NOT ERASE/TEST</MESSAGE>

</MT_I_RFC>

<MESSAGE> is 0:1.

In my mapping I need to take the content in <MESSAGE> and when I find / in the message, the content needs to be split into multiple resulting tags like below

structure of result is

<MT_FF>

<ROW>

<MESSAGE></MESSAGE>

</ROW>

</MT_FF>

<ROW> and <MESSAGE> is 0..unbounded.

After mapping the above input the result should be:

<MT_FF>

<ROW>

<MESSAGE>TEST MESSAGE</MESAGE>

</ROW>

<ROW>

<MESSAGE>DO NOT ERASE</MESSAGE>

</ROW>

<ROW>

<MESSAGE>TEST</MESSAGE>

<ROW>

</MT_FF>

can I please know how to achieve this? thanks for your help in advance.

Edited by: developer on Jul 8, 2008 5:50 AM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Assuming source element MESSAGE occurrence is 0..1 and that of target elements ROW and MESSAGE is 0..unbounded, you can do something like this -

Map source element MESSAGE to target element MESSAGE using UDF split() shown below -

public void split(String[] a,ResultList result,Container container){
   int i;
   String [] temp = a[0].split("/");
   for( i = 0; i < temp.length; i++ ) {
      result.addValue(temp<i>);
      result.addContextChange();
   }
}

And map source element MESSAGE to target element ROW using UDF split2() shown below -

public void split2(String[] a,ResultList result,Container container){
   int i;
   String [] temp = a[0].split("/");
   for( i = 0; i < temp.length; i++ ) {
      result.addValue(temp<i>);
   }
}

Edit: These are advanced UDFs. i.e. while creating the UDFs, under Cache, select the radio button next to Queue. This allows you to modify the entire message queue in the UDF.

Hope this helps.

Regards,

Riyaz

hashtag_siva
Explorer
0 Kudos

Thanks. it worked

Answers (1)

Answers (1)

moorthy
Active Contributor
0 Kudos

Hi,

You can achieve this using Java Code/user defined function or Java Mapping, where you can generate the target structure as you required... So use Java Code to achieve the same

Regards, Moorthy

hashtag_siva
Explorer
0 Kudos

Thanks. I am new to this. can i know what the java code should be?

Former Member
0 Kudos

Hi,

Its possible with adding advanced UDF. Even you can existing Node Functions also such as SplitByValue, etc..

Please can you give me the data that you will be sending as input from Source mapping, whihc have formated to target mapping as given in your previous post, so I can try for exact solution

<MT_FF>

<ROW>

<MESSAGE>TEST MESSAGE</MESAGE>

</ROW>

<ROW>

<MESSAGE>DO NOT ERASE</MESSAGE>

</ROW>

<ROW>

<MESSAGE>TEST</MESSAGE>

<ROW>

</MT_FF>

Thanks

Swarup

Edited by: Swarup Sawant on Jul 8, 2008 7:54 AM