cancel
Showing results for 
Search instead for 
Did you mean: 

How to Extract particular field from a string ( Mapping)

Former Member
0 Kudos

how to exteract the particular field from the given string:

ProcessEmp this element has a below string subfields.

<ProcessEmp>&lt;?xml version="1.0" encoding="utf-8" standalone="no"?&gt;

&lt;Employee PersonnelNumber="11111" FirstName="String" MiddleName="String" LastName="String" Department="String" Group="" SapUserID="10flname" EmailAddress="flname@mu.edu" DefaultPassword="*" Status="Success" /&gt;</ProcessEmp>

how to extract only PersonalNumber, department, EmailAddress from above ProcessEmp into 3 diff fields.

Thanks

dhanush.

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi,

You are receiving XML message within a field. To access a particular field from that XML message, you could create a User Defined Function, as suggested by many already.

You could write UDF using some of the String operation functions. This could include following:

1. If you need to access field Employee PersonnelNumber, you could get last index of that within string using function lastIndexOf(String str). Pass string "Employee PersonnelNumber="" for this function.

2. This function would return an index of rightmost occurance of this string.

3. after this you could get the index of next occurance of ", as the value of field is within quotes. You could use function indexOf(int ch, int fromIndex) for getting the same. You would pass Character as " and index as the one received by previous function.

4. Now you have index for starting and ending point of value string for desired field.

5. After this you could use substring(int beginIndex, int endIndex) function by passing first and second index values to retrieve the needed string, which contains value of field.

Hope this would be helful.

Thanks,

Bhavish

    • Reward points if comments found helpful:-)

Former Member
0 Kudos

> ProcessEmp this element has a below string

> subfields.

>

> <ProcessEmp><?xml version="1.0" encoding="utf-8"

> standalone="no"?>

> <Employee PersonnelNumber="11111"

> FirstName="String" MiddleName="String"

> LastName="String" Department="String" Group=""

> SapUserID="10flname" EmailAddress="flname@mu.edu"

> DefaultPassword="*" Status="Success"

> /></ProcessEmp>

As u mentioned the XML messaeg is coming in the ProcessEmp element. so in ur mapping this will simply act as a string and u have to perform manipulation on it to get the expected values.

so just write a UDF and return the value from it.

example:

source = ProcessEMP

target = PN (where u have to map the value of the PersonalNumber.)

so just write a UDF which will accept that whole String and return only 1111.

What u have mentioned is just a String which look like a XML message..but u cannot map the fields directly...

Thanks

Farooq.

Former Member
0 Kudos

Can you please send me the Java code to create UDF for extractig particular field from the given string.

thanks

dhanush

Former Member
0 Kudos

Dhanush,

As I said earlier U will have to do the following

1.) In the mapping create a user defined funtion

2.) In the pop up box give a name to ur function like ExtractEmpNo

this should be of the type Value.

3.) Then in the code section write the following simple code

String result[] = a.split("\"");

return result[7];

4.) keeping it simple spliting with " sign , so u have to either calculate the

number of " before Personnel number Or

5.) u can improvise the code if U like it to be more generic

else for retireving rest of the field values simple just calculate

Get back if U have any issues.

Regards

Kavitha

justin_santhanam
Active Contributor
0 Kudos

Dhanush,

The parameters which you have given inside the employee node are Attributes of the employee. In this case map the attributes you needed to the target structure directly. It will solve your issue.

raj.

Former Member
0 Kudos

Hi Raj,

when i imported WSDL ProcessEmp, it does not showing attributes under ProcessEmp, it just shoing ProcessEmp witch will have below string.

ProcessEmp this element has a below string subfields.

<ProcessEmp><?xml version="1.0" encoding="utf-8" standalone="no"?>

<Employee PersonnelNumber="11111" FirstName="String" MiddleName="String" LastName="String" Department="String" Group="" SapUserID="10flname" EmailAddress="flname@mu.edu" DefaultPassword="*" Status="Success" /></ProcessEmp>

how to extract only PersonalNumber, department, EmailAddress from above ProcessEmp into 3 diff fields.

Former Member
0 Kudos

how did you import your WSDL,was it like "From all avalable ...."?

Former Member
0 Kudos

Hi Babu,

Frome External Def in IR.

thanks

dhanush

Former Member
0 Kudos

I am not asking that buddy....everybody knows that

again when you choose WSDL there will be three options in the dropdown box next to WSDL selection box.

there ,how you are selecting the messag?

Former Member
0 Kudos

Hi Dhanush

It seems ur getting this XML inside another element

also if Ur using Graphical Mapping

then :

1.) Create a new User Defined Funtion.

2.) Use String Tokenizer with equals sign ("=")

3.) and collect the values into variables.

Regards

Kavitha

Message was edited by:

Kavitha Golagani

Former Member
0 Kudos

how you have your source structure?

did you import any XSD for that?looks like ,mentioned fields are attributes.

>>how to extract only PersonalNumber, department, EmailAddress from above ProcessEmp into 3 diff fields

just map from source to target fields.