cancel
Showing results for 
Search instead for 
Did you mean: 

Splitting a string in message mapping

Former Member
0 Kudos

Dear All

One of my scenarios receive a payload in the following format

<?xml version="1.0" encoding="UTF-8" ?>

<ns0:MT_String xmlns:ns0="http://scb.com/xi/payment/10">

<person>name=John&lastname=Smith&city=ny&country=USA&zip=&region=Americas</person>

</string_MT>

</ns0:MT_String>

I am trying to split the <text> parameter & delimited into a new structure that will look as follows:

<?xml version="1.0" encoding="UTF-8" ?>

<ns0:MT_String_split xmlns:ns0="http://hr.com/">

<person>

<name>John</name>

<lastname>Smith</name>

<city>ny</city>

<country>USA</country>

<zip></zip>

<region>Americas</region>

</person>

</ns0:person>

Can somebody please advise that how this can be done?

Will grant highest point for the coplete answer.

Thank you

Haik

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

you have to build a UDF to achieve this.

2 inputs: the complete string and the variable name (e.g. name)

1 output: the value

You could user java regular expressions and define that the value you are looking for is always after the "variable name" and always before a & or a <.

Kind Regards,

Sergio

Former Member
0 Kudos

Hi Sergio

Thanks for the prompt answer. will you be able to give some more hints that how teh UDF will look llike?

Thanks

Haik

Former Member
0 Kudos

Hi Haik,

it should look more or less like this:

import java.util.regex;

String strRegex;
String strOpenTag;
String strCloseTag;

int lenOpenTag;
int lenCloseTag;

strOpenTag = your_variable_name;
srtCloseTag = "[&|<]";

lenOpenTag = strOpenTag.length();
lenCloseTag = strCloseTag.length();

strRegex = strOpenTag + ".*" + strCloseTag;
Pattern p = Pattern.compile(strRegex);
Matcher m = p.matcher(your_xmlStringInput);

while(m.find()){
return your_xmlStringInput.substring(m.start()+lenOpenTag ,m.end()-lenCloseTag);
}

return "error";

Ciao,

Sergio

Former Member
0 Kudos

Hi Haik,

if the issue is solved do not forget to close this thread.

Regards,

Sergio

Former Member
0 Kudos

Also you can look at the SAP XI wiki at

https://www.sdn.sap.com/irj/scn/wiki

and look for " How to append Carriage Return in the end of each tag of xml file "