cancel
Showing results for 
Search instead for 
Did you mean: 

Need Help In Mapping

Former Member
0 Kudos

Hi All,

I have a scenario in which I need to perform the following mapping logic:

Source Structure:

<SrcMsg>

<Node1>

<Details>"<Name>XYZ</Name><Description>Desc1</Description><Id>ID123</Id>"</Details>

</Node1>

</SrcMsg>

Target Structure:

<TrgMsg>

<Node1>

<TargetID>ID123</TargetID>

</Node>

</TrgMsg>

i.e. I need to extract the data from Id tag within Details of Source message.

The Details node will have the following data as string

<Name>XYZ</Name><Description>Desc1</Description><Id>ID123</Id>

Thanks,

Abhishek.

Accepted Solutions (1)

Accepted Solutions (1)

former_member518917
Participant
0 Kudos

Hi,

write a UDF:

{

int i = a.indexOf("<Id>");

int j = a.indexOf("</Id>");

return a.substring(i+4,j);

// 4 'coz length of "<ID>" is 4

}

Edited by: Ritu Sinha on Oct 14, 2008 2:17 PM

Answers (5)

Answers (5)

former_member200962
Active Contributor
0 Kudos

Hi,

Thanks for all those helpful answers.

In the same mapping program I am having another issue:

<Source>

<SRCNode>(0..unbounded)

<Code>(0..1)

</Number>(0..1)

</Code>

</Description>(0..1)

</SRCNode>

</Source>

<Target>

</TRGTNode>(0..unbounded)

</Target>

Here I have implemented the logic If Number = 10 & Description exists then map SRCNode to TRGTNode i.e TRGTNode should repeat for all SRCNodes who have Field = 10.

The problem that I am facing is TRGTNode is repeating only for the first instance of Number = 10 and not for all the other instances of Number = 10.

Thanks,

Abhishek.

Edited by: abhishek salvi on Oct 15, 2008 1:41 PM

SudhirT
Active Contributor
0 Kudos

Hi Abhishek,

Check with the display queue functionality whether you are getting equal no. of context for both the inputs in IF condition if not then change the context of Number or Description accordingly.

Thanks!

Former Member
0 Kudos

Hi Avishek,

This is certainly related to the context of the source node. You need to adjust the context from the source according to you mapping requirements using either a standard function or simply setting the context of the source node to different levels of context. Though I believe (by reading your problem statement) simply using the standard function "Remove Context" at the end of the mapping logic for Target Node would solve your problem. Let us know if this works for you.

Regards,

Suddha

SudhirT
Active Contributor
0 Kudos

Hi Abhishek,

Write UDF exactly like

String b = "";

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

b = a square bracket i.substring( a square bracket i.indexOf("Id") +3, a square bracket i.lastIndexOf("Id") - 2);

result.addValue(b);

Here source will be Detail field and Target will be Target ID.

Thanks!

Edited by: sudhir tiwari on Oct 14, 2008 11:08 AM

Former Member
0 Kudos

Use XSLT Mapping if the mapping is same for the whole XML doc.

Regards

prateek
Active Contributor
0 Kudos

If the type of data is always same, u may simply substring till index of <ID> and then use the remaining data for mapping. Standard functions or UDF could be used in such case.

Regards,

Prateek

former_member190389
Active Contributor
0 Kudos

Hi,

write a UDF for TargetID with Details tag as input to it.


int i1 = details.indexOf("<Id>");
int i2 = details.indexOf("</Id>");
return (details.substring(i1+4,i2));

santhosh_kumarv
Active Contributor
0 Kudos

Hey,

This is a simple and straight forward mapping.

Just map the source Id to target node TargetID.

Ohh.. if the input is a string then you would require a UDF to extract the value

Thanks

SaNv...

Edited by: Sãnthosh Kûmãr V on Oct 14, 2008 2:18 PM