on 07-23-2007 7:01 PM
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.
You would have to use XSL or Java Mapping . This is not possible with Graphical Mapping.
Regards
Bhavesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.