on 05-07-2008 7:09 AM
Hi all,
I am doing a file to file scenario in which we need to split the data coming in a single node of the source structure to multiple nodes in the target structure.
For eg:
The source structure is something like this:
<Name>abcd;xyzw;prs</Name>
and the target structure is something like:
<FirstNAme>abcd</FirstNAme>
<MidNAme>xyzw</MidName>
<LastName>prs</LastName>
the length of the data is not fixed. and ";" is used as a seperator.
I have hundred such nodes on the target side.
How do i acheive this
.
Please help.
Thanks and Regards,
neha
Hi Neha,
You have to write UDF for Spliting.
I just to confirm that from <Name> element the data is going to <FirstNAme>,<MidNAme> and <LastName> as per your example,always do you get 3 values in <Name> element?
Like <Name> element what are the other Elements you have?
Cheers,
Jag
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There is a little mistake in the codes posted above.
the correct one:
String[] splitCodes = null;
for(int i = 0; i < inputVal.length; i++)
{
if( !(inputVal<i>.equals("")))
{
splitCodes = inputVal<i>.split(";");
for(int j = 0;j<splitCodes.length;j++)
{
result.addValue(splitCodes[j]);
}
}
}
--Sankar Choudhury
Hello,
I wouldn't use Java for this at all. I'd use XSLT, which you can kick off from Java. Doing this with pure Java will be painful, tiresome to write and bug-ridden, whereas it's exactly what XSLT is there for. Don't do the predictable thing and shy away from learning XSLT, it's an extremely useful skill to have in your toolkit, and ideal for your problem. It's also pretty simple to learn
http://www.w3schools.com/xsl/default.asp
And alo you can do this by....considering Sender File Content conversion and to convert to Target file use split by value node function
***********Reward points,if found useful
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Create one UDF as Type Context
String[] splitCodes = null;
for(int i = 0; i < inputVal.length; i++)
{
if( !(inputVal<i>.equals("")))
{
splitCodes = inputVal<i>.split(";");
for(int j = 0;j<splitCodes.length;j++)
{
result.addValue(splitCodes[j]);
}
}
}
I consider Your input value as inputVal
Do mapping as
InputVal --> RemoveContext -- > UDF --> SplitByValue --> Target field
Regards,
Rohit.
Reward points if helpful.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
try this function
//write your code here
String [] vals = null;
for (int i=0; i<a.length; i++) {
vals = a<i>.split(";");
for (int j=0; j<vals.length; j++) {
result.addValue(vals[j]);
}
}
it will work.
and its occurence should be unbouned are some number.
Edited by: srikanth vipparla on May 7, 2008 8:57 AM
Edited by: srikanth vipparla on May 7, 2008 8:58 AM
Edited by: srikanth vipparla on May 7, 2008 9:03 AM
write a UDF taking Name as input parameter
String [ ] StrArray = SourceFileName.split(";");
result.addValue(StrArray(count)); // square brackets
where count is another parameter to UDF which will send 1 st value to FirstName, 2nd to MiddName.. accordingly.... pass 1, 2 constant accordingly as count
Edited by: Mugdha Kulkarni on May 7, 2008 8:25 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
101 | |
13 | |
13 | |
11 | |
11 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.