cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping Issue - Context Changes

Former Member
0 Kudos

Hello all. I am working on a file - file scenario, XML - XML. My messages look as follows:

<u><b>Source:</b></u>

-<header> (1..unbounded)

---<field1>test</field1> (1..unbounded)

---<field2>test2</field2> (1..unbounded)

---<field3>1,2,3,4</field3> (1..unbounded)

-</header>

<u><b>Target:</b></u>

-<header> (1..unbounded)

---<field1>test</field1> (1..1)

---<field2>test2</field2> (1..1)

---<fieldTree> (1..unbounded)

-


<subField1>1</subField1> (1..1)

---</fieldTree>

---<fieldTree>

-


<subField1>2</subField1>

---</fieldTree>

---<fieldTree>

-


<subField1>3</subField1>

---</fieldTree>

---<fieldTree>

-


<subField1>4</subField1>

---</fieldTree>

-</header>

I have a UDF that creates the fieldTree contexts based on the number of items in field3 of source deliminated by comma. Another UDF to split the values and place into the subField positions.

That works fine, however when there are multiple entries of the source message, similar to:

<header>

<field1>test</field1>

<field2>test2</field2>

<field3>1,2,3,4</field3>

</header>

<header>

<field1>test3</field1>

<field2>test4</field2>

<field3>5,6,7,8</field3>

</header>

I receive this error:

<i>Cannot produce target element /ns0:test_XML/header[2]/fieldTree. Check xml instance is valid for source xsd and target-field mapping fulfills requirements of target xsd</i>

If I disable the fieldTree field in target message it works fine. The mapping looks like this:

<u>target / source</u>

header / header

field1 / field1

field2 / field2

fieldTree / (UDF) field3

subField1 / (UDF) field3

My guess is it's something very simple that I am overlooking. Or some way that XI handles this sort of thing that I do not understand that could possibly be throwing errors at me. Anyone have any ideas to point me in the right direction?

Accepted Solutions (1)

Accepted Solutions (1)

STALANKI
Active Contributor
0 Kudos

I think you are missing the outerloop.Because when u are using two instances of the header..then it will be input[0] and input[1].Hope u understood what u meant,

It is not just input[0].split().but all the code has to have outer loop.

Former Member
0 Kudos

Sravya, this makes a bit of sense. I had thought that XI would process and pull in the values procedurally, rather than pull all the values in ahead of time and then process them. I added an outer loop, and it didn't work. So I am trying to debug the issue and I changed the input[0] to input[1] and I got an error. So I believe that maybe it's not pulling in the second set of values from the second instance of field3. Could this be the case? How would I solve this issue?

Former Member
0 Kudos

Okay, so I almost have it working, when I make input[2]. For soem reason I have to go from [0] to [2] to [4] to read the input values, rather than [0] to [1] to [2]. This is very strange.

Former Member
0 Kudos

Is there a way I can detect how many instances of <header> there will be so I know how long to make the outer loop for?

Former Member
0 Kudos

nevermind, I got it done. thanks for all your help

Answers (2)

Answers (2)

STALANKI
Active Contributor
0 Kudos

yes,u can by accessing the length of input.

STALANKI
Active Contributor
0 Kudos

Have u gone through this?

/people/sravya.talanki2/blog/2005/08/16/message-mapping-simplified--part-i

/people/sravya.talanki2/blog/2005/12/08/message-mapping-simplified-150-part-ii

Former Member
0 Kudos

Yes I have read those. I am not sure if it applies to me because I am using UDF's to do context changes rather than the graphical editor. I think the problem is something small that I am overlooking.

Former Member
0 Kudos

My UDF for the fieldTree looks like this:

<i>String x[] = input[0].split(",");

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

result.addValue(" ");

}

</i>

And the UDF for subField1 looks like this:

<i>String x[] = input[0].split(",");

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

result.addValue(x<i>);

result.addContextChange();

}</i>

The first one creates the contexts and the second splits up the values in field3 of source message and places them into the contexts.

Message was edited by:

Harrison Holland