cancel
Showing results for 
Search instead for 
Did you mean: 

complex .csv to xml conversion

Former Member
0 Kudos

Hi ,

  i need to convert .csv file into xml . File structure of .csv file is like this.

    

  Header -  field1, field 2, field3, field4, field5, field6,field7,field8,field8,field8, field9,field10

  Line1      -  Lineitem-field1,Lienitemfield2(field8), Lineitem-field3,Lienitemfield4, Lineitem-field5,Lienitemfield6

  Line 2     -  Lineitem-field1,Lienitemfield2(field8), Lineitem-field3,Lienitemfield4, Lineitem-field5,Lienitemfield6

  Line3      -  Lineitem-field1,Lienitemfield2(field8), Lineitem-field3,Lienitemfield4, Lineitem-field5,Lienitemfield6

  Trailer   -  Trailer-fiield.


  Here you can see that in Header -  Field8 is coming multiple times and on the basis of the occurrence this field, line items rows are created 3 times.

and field8 is also coming as Lienitemfield2 in Lines.


  This recordset can have multiple records of   Header,1,Line*,Trailer ,1.

     <Recordset> 1..unbounded

         < Header> 1..1

           <Line>  1..unbounded

           <Trailer> 1..1 


My question is if this requirement can be handle in FCC or i need to handle this using UDF / java mapping.

Please suggest.


Regards,
RB

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

For reading fields using FCC ,you need to have key field for each record in order to distinguish b/w header,body,footer records.

>>Here you can see that in Header -  Field8 is coming multiple times and on the basis of the occurrence this field, line items rows are created 3 times.

For your case you need to handle as below ,because field 8 repeats.

1)Use the below fcc and input structure as explained in the below blog

2)Mapping 1 is to read record by record/line by line and put it in actual structure.

Key for you is field8 occurs no of times body record repeats .So based in this you can write an udf similar to the above link and capture the values in actual struture.

3)Mapping 2 is b/w actual structure and to your target structure .

Regards

Venkat

Former Member
0 Kudos

Thanks Venkat for your suggestion.

but here in your case columns are jumble in incoming file and fields occurance is fixed. and you have read first all the values of record and then in mapping 2 distribute the values to respective columns os traget structure.

in my case structure is nested and in Header - one field (for eg. field8) may occurs may times.

My traget structure is a standard Idoc.

Please suggest on this.

Former Member
0 Kudos

Hi,

I'm not asking you to copy as it is .Create an udf as per your requirement .

Give the AssetData_Value field value as an Input to udf  say BodyVal.

BodyVal contain n number of records

BoduVal[0] contains your header record,

String Header[] = BodyVal[0].split(",");

int Count_Field8 = Header.length - 9 ;

Header_field1.addValue(Header[0]);

.

.

.

.

Header_field7.addValue(Header[6]);

int j=7

for(int i=0;i<Count_Field8;i++){Header_field8.addValue(Header[j++]);}

Header_field9.addValue(Header[j++]);

Header_field10.addValue(Header[j++]);

...

int l =1

for(int k=0;k<Count_Field8;k++)

{

String Bodyrec[] = BoduVal[l++].split(",") ;

//populate body values to respective fields

}

String Footer[] = BoduVal[l].split(",");

//populate footer values to respective fields

Take the core logic from the above rough code .Let me know if you struck with any issue .I don't want to spoon feed so I just given core logic to implement by leaving fine tuning the code job to you.

Regards

Venkat

Answers (0)