Skip to Content
avatar image
Former Member

complex .csv to xml conversion

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    avatar image
    Former Member
    Aug 12, 2014 at 01:26 PM

    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

    Reading a delimeter separated file whose columns may jumble

    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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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

      Map1.JPG (57.0 kB)