cancel
Showing results for 
Search instead for 
Did you mean: 

useOneAsMany and splitByValue

Former Member
0 Kudos

Hello all.

I am attempting to take an XML structure similar to this:

<u><b>source</b></u>

-<recordset>

-


<header>

-


<element1>12,34,56,78</element1>

-


</header>

-</recordset>

And using a target data type similar to this:

-<recordset>

-


<header>

-


<subtree1>

-


<element1>

-


</subtree1>

-


</header>

-</recordset>

<u><b>Create a result of:</b></u>

-<recordset>

-


<header>

-


<subtree1>

-


<element1>12</element1>

-


</subtree1>

-


<subtree1>

-


<element1>34</element1>

-


</subtree1>

-


<subtree1>

-


<element1>56</element1>

-


</subtree1>

-


<subtree1>

-


<element1>78</element1>

-


</subtree1>

-


</header>

-</recordset>

I have done several tests, and I've gotten the <i>splitByValue</i> function to work when there are multiple instances of <element1> in the source file. However, I need to basically do a splitByValue when there is only one instance of <element1>, but with the multple variables in that field.

I'm thinking if I can find a way to combine <i>useOneAsMany</i>, <i>splitByValue</i>, and something else, I can accomplish this goal. Does anyone have any hints? Or know if I'm even on the right path?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Harrison, you have to use a user defined function to split your element into several output elements.

Example code would look like this:


yourUserDefinedFunction(String[] a, ResultList result,Container container) {
    String[] str = null;
    str = a.split(",");

    for(int j=0;j<str.length;j++) 
        result.addValue(str[j]);
       
}

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Harrison,

I think you need a udf to achieve your aim:

function type: queue

function name: splitComma

input: String[] strInput

output: ResultList rstQueue

for ( int i=0; i<strInput.length;i++){

StringTokenizer st = new StringTokenizer (strInput<i>, ",");

while (st.hasMoreTokens ())

rstQueue.addValue(st.nextToken());

}

Now, for your requirements you should do mapping in this way:

out:recordset = in:recordset

out:header = in:header

out:subtree1 = splitComma(in:element1)

out:element1 = splitByValue(splitComma(in:element1))

Hope It helps.

Kind Regards,

Sergio