cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping question

Former Member
0 Kudos

All

I have a source structure like.

<Source>

<DataLoadID>1</DataLoadID>

<Data>

<Employee>

<Name>John Q</Name>

<Title>Senior Engineer</Title>

</Employee>

<Employee>

<Name>John Q</Name>

<Title>Senior Engineer</Title>

</Employee>

<Employee>

<Name>Sam H</Name>

<Title>Manager</Title>

</Employee>

</Data>

</Source>

we have a target structure as follows,

<Target>

<DataLoadID>1</DataLoadID>

<RawData></RawData>

</Target>

The requirement is in the target <RawData> node should have all the data that is within the <Data> node in the source (basically the xml text of the <Data> node).

How can we do this in the graphical mapping? (or user defined function)

Thanks.

Accepted Solutions (0)

Answers (2)

Answers (2)

bhavesh_kantilal
Active Contributor
0 Kudos

You would have to use XSL or Java Mapping . This is not possible with Graphical Mapping.

Regards

Bhavesh

Former Member
0 Kudos

You can create a generic function in your UDF that takes 2 vals

1) mode

2) string

In your UDF, if the mode is init, initialize a global container, create a parameter "raw_data" and add a string to this parameter (i.e. concat).

Every subsequent call should be mode = repeat and for this mode, just add the string to your parameter.

At the end of your xml map - assign the final value of parameter raw_data to your target string.

You can also implement checks for nulls etc

sincerely,

--NM

bhavesh_kantilal
Active Contributor
0 Kudos

Naomi,

Thats an interesting way.

If I can improvise your procedure,

1. Use Advanced UDF's with 2 inputs. One the FIELDNAME hardcoded ( Constant ) and the second the values .

2. The UDF is called for every source field and so on.

3. Just a quick pointer that , using Global Variables of the java Section would be more useful than using Global Container -- both from ease of use and from a performance perspective.

Nice way to do this though Thanks for the Idea.

Regards

Bhavesh

justin_santhanam
Active Contributor
0 Kudos

Bhavesh/Naomi,

I couldn't understand the logic. Can u explain a lil bit?

Best regards,

raj.

Former Member
0 Kudos

duly noted...

FYI to the OP

the UDF I had will give you values only - not tags and values.

i.e. <Raw_Data>john</Raw_Data> NOT <Raw_Data><name><john></name></Raw_Data>

The one described by Bhavesh since it has the fieldname hard-coded will have the entire string.

Sincerely,

--NM

justin_santhanam
Active Contributor
0 Kudos

Hello,

Do you want the Raw data as below output.

<RawData><Data><Employee><Name>John Q</Name><Title>Senior Engineer</Title></Employee><Employee><Name>John Q</Name>

<Title>Senior Engineer</Title></Employee><Employee><Name>Sam H</Name>

<Title>Manager</Title></Employee></Data></RawData>

Best regards,

raj.

Former Member
0 Kudos

yes. that is right raj. That is how we want the target format.

Message was edited by:

thezone

justin_santhanam
Active Contributor
0 Kudos

Hello,

As Bhavesh suggested ,u have to carry these forward using either Java or XSL mapping. I'm really sorry , I haven't worked on both the mappings.

Best regards,

raj.

justin_santhanam
Active Contributor
0 Kudos

Hi,

I don't know did u solved ur issue or not. But see the below blog from Michal, it will be more helpful.

/people/michal.krawczyk2/blog/2005/11/01/xi-xml-node-into-a-string-with-graphical-mapping

I'll try to work out the same. If you have any doubts ,do reply back.

Best regards,

raj.

Former Member
0 Kudos

Naomi / Bhavesh / Raj,

Im not that familiar with the Advanced user defined functions - can you let me know what the user defined function will look like? a sample code will be appreciated.

Thanks.

Former Member
0 Kudos

Also - since there is only one target node (rawdata), how can we map all the different source fields plus different constants to the same target node?

Thanks for the help.

Former Member
0 Kudos

Few things to note:

1) when mapping, XML travels down the XML structure

2) I have not validated this so you should run a syntax check.

3) There are many ways to do this, you can make the syntax cleaner

4) If your last field has to be added, you can change to 4 input parameters where the 4th is retrieve and mode is only 1 & 2 (init and append)

5) This uses containers not variables.

anyways................

***Create UDF with the following Input parameters

1) Field_name 2) field_str 3) Mode

***Code:

GlobalContainer GContainer = container.getGlobalContainer();

***create the new string with tags etc

String NewStr = "<" + field_name + ">" + field_val + "<" + field_name + "/>";

      • place holder for container value and return value

String currStr = "";

String retStr = "";

      • check the mode and perform activities as required

int imode = new Integer(mode).intValue();

switch (imode) {

case 1: //init set the value in container

GContainer.setParameter ("raw_data",NewStr);

case 2: //append - add the value to container

currStr = (String)GContainer.getParameter("raw_data");

currStr = currStr + NewStr;

GContainer.setParameter ("raw_data",NewStr);

case 3: //retrieve - get the final value

retStr = (String)GContainer.getParameter("raw_data");}

return retStr;

      • you will only use the retrieve mode at the end of your mapping.

sincerely,

--NM

Former Member
0 Kudos

Thanks for your quick reply. How will this look in the graphical mapping editor?

<Data> -> UDF -> <RawData>

How will the other nodes be mapped? or am i missing something here?

Thanks.