Skip to Content
author's profile photo
Former Member

How to Extract particular field from a string ( Mapping)

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;

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

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

Thanks

dhanush.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

5 Answers

  • Oct 11, 2007 at 03:48 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Oct 11, 2007 at 03:55 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 11, 2007 at 04:07 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

    • 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?

  • author's profile photo
    Former Member
    Oct 11, 2007 at 06:15 PM

    > 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.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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

  • author's profile photo
    Former Member
    Oct 12, 2007 at 11:27 AM

    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:-)

      Add comment
      10|10000 characters needed characters exceeded