cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping question

Former Member
0 Kudos

Hello all.

i am trying this mapping where my source has 3 msgs:

msg1

msg2

msg3 , msg 3 has header and line item. In this msg 3 the header will occur only once and line item will occur multiple times.

My target has only 1 msg with elements ABCDEFG etc..

What i am trying to do is:

for every occurence of an element in the line item of msg 3 i have to map it to the target elements ABCDEFG.

for example:say in msg 3, the line item has this element called Codevalue. let s assume it occurs 5 times. for its first occurence it has to be mapped to target element A, for its second occurence it has to be mapped to target element B, for third occrence mapped to target element C and so on..

can somebody help me with a solution please??...

Thanks

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Dimitry,

Thanks for your reply.

1) I created this simple function and i mapped this function directly to my target elemnt. i understand that this function replaces the source field by another name and just gives the same value....but does this function work when multiple occurence of a particular lineitem elements have to mapped to different target elements?? I tried the way you said but it did not work.Please advice

Former Member
0 Kudos

Hi

Actually I told you the way how to do that and not the complete solution.

You can use 2 arguments for your function.

The first one is "lineItem" and the second one "lineItem"->Index(the function from statistic group)

and the code should look like


((AStructureNode)container.getParameter("STRUCTURE_NODE")).setQName("myName"+b);
return a;

With this function if you have 5 line items then you'll get

myName1=lineItem[1]

myName2=lineItem[2]

myName3=lineItem[3]

myName4=lineItem[4]

myName5=lineItem[5]

I suppose ABCDE and so on was not the real names of your target field In the function based on argument "b" which contains the position of your line item you can generate any field name.

Regards

Dmitry

Former Member
0 Kudos

Even more interesting.

I found out that one can also add new namespace declaration and new attributes to the node


LeafStructureNode node =((LeafStructureNode)container.getParameter("STRUCTURE_NODE"));
node.setQName("ns:anotherName");
node.setNSDeclarations(" someAttr="2" xmlns:ns="myNamespace"");
return a;

It works also with leafs and structured fields.

Doesn't work for attributes.

And this code works only for structured fields (those one that have subfields)


StructureNode node =((StructureNode)container.getParameter("STRUCTURE_NODE"));
node.setQName("ns:anotherName");
node.setNSDeclarations(" someAttr="2" xmlns:ns="myNamespace"");

node.setPreValue("somePrefix<b>You can put the whole xml here as it is not"+
  " escaped</b>. Of course it should be valid xml,"+
  "otherwise the whole target payload will be invalid.");
node.setPostValue("somePostfix");

return a;

So if you want to put arbitrary xml into some field you can use setPreValue or setPostValue. The only thing that your target field should be a structure. But you can make subfields optional and without mapping. Then you'll have a field containing any string value as a content.

Best regards

Dmitry Yankovsky

Former Member
0 Kudos

Hi

You can change a name of generated field using the following simple function

This function just return the same value that receives but also replaces the target field name.


((AStructureNode)container.getParameter("STRUCTURE_NODE")).setQName("anotherName");
return a;

This function should be mapped to the target field directly. Otherwise the container will not contain the parameter ("STRUCTURE_NODE").

Actually you can put any name and add any functionality to such function. That's just example how to change the name of the target field in the runtime. Your target structure then doesn't valid to your XSD but whatever

Instead of "anotherName" you can also use prefixed name as "ns:anotherName" but this prefix should be already declared before.

Best regards

Dmitry