cancel
Showing results for 
Search instead for 
Did you mean: 

Create user-defined function with xml

Former Member
0 Kudos

Hi,

I need to do a user defined function inside a mapping where i want the result to be an XML:

from fields are string 1 and string 2. that needs to create a result like this:

<Header xmlns="http://namespace1"><User>[string1]</User><Pass>[string2]</Pass></Header>

How could that be done (i need som JAVA help )

/Jakob

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

try this one (the input parameters of the UDF are String1 and String2):

String result = new String();
result = '<Header xmlns="http://namespace1"><User>' + String1 + '</User><Pass>' + String2 + '</Pass></Header>';

return result;

Dominic

Edited by: Dominic Ludolph on Feb 25, 2008 9:18 AM

Answers (5)

Answers (5)

Former Member
0 Kudos

Thank God that we have ABAP I have solved the problem with inspiration of the blog from Michal Krawczyk...

The User-Defined function return the xml with &lt; and so on. And then i add an ABAP mapping in the Message Mapping who replaces the signs '&lt;', '&gt;' and '&quote&.

Maybee not the nicest solution - but it works!

Thanks for all your help...

/Jakob

Former Member
0 Kudos

Hi,

Well i´ve got something to work, but still i have some problems: it seems that the < and > are translatet to &lt; and &gt; and the browser the consider the xml as text?

What is wrong?

/Jakob

Former Member
0 Kudos

Hi,

It will be translated that's the standard. In my opinion you won't achieve that in graphical mapping at least not in UDF.

Please check that website:

http://www.w3schools.com/xml/xml_cdata.asp

But I think that it won't satisfy you.

/wg

Edited by: Wojciech Gasiorowski on Feb 25, 2008 8:09 PM

Former Member
0 Kudos

Hi,

If you are looking for some thing like this means , Have a look at this BLOG

/people/michal.krawczyk2/blog/2005/11/01/xi-xml-node-into-a-string-with-graphical-mapping

Regards

Seshagiri

Former Member
0 Kudos

Hi,

I thin kboth are on the way - BUT the "//" in the namespace gives me some problems because it is interpreted as an Comment?

This means that after the // the code is commented out?

Former Member
0 Kudos

You're right. Then you have to concat the fields. Try This one:

String result = new String();
result = Const1 + String1 + Const2 + String2 + Const3;
return result;

Const1-3 are Constants where you put in the XML parts:

Const1: <Header xmlns="http://namespace1"><User>

Const2: </User><Pass>

Const3: </Pass></Header>

Former Member
0 Kudos

Hi Dominic,

Well - how do i declare the Constants then?

henrique_pinto
Active Contributor
Former Member
0 Kudos

Hi,

You define a UDF with the 5 input variables Const1, String1, Const2, String2 and Const3.

Than you mapp the funtion:

- Constant with your XML value (you find Constant under the standard functions Constants)

- String1 (this is your value from the source

- Constant with your XML value (you find Constant under the standard functions Constants)

- String2 (this is your value from the source

- Constant with your XML value (you find Constant under the standard functions Constants)

Dominic

Jitendra_Jeswan
Contributor
0 Kudos

Create any UDF with cache as Value.

Input the 2 Strings you want to use in XML as the Input parameters in the UDF

and Add the following line of code.

// Write code here

String xmlOutput = null ;

xmlOutput = "<Header xmlns=\"http://namespace1\"><User>"string1"</User><Pass>"string2"</Pass></Header>";

return xmlOutput;

// code ends

Hope this helps.

Reward points if found helpful.