Smooks, Read CSV, get First Record as Header info and process the rest as Records

816 views Asked by At

I am stuck on a situation where I have to read a CSV file Smooks, and split the same into small CSV or XML files. I have tried this against a big XML file which I split and transformed into another form of an XML object-it worked fine. But in this case, I have a CSV file similar to this.

HEADER,val01,val02,,,
LINE,lineVal01,lineVal02,lineVal03,lineVal04,lineVal05
LINE,lineVal01,lineVal02,lineVal03,lineVal04,lineVal05
LINE,lineVal01,lineVal02,lineVal03,lineVal04,lineVal05
LINE,lineVal01,lineVal02,lineVal03,lineVal04,lineVal05

While doing the java bean binding, I need to read this header separately and generate small CSV/XML files that represent each LINE record containing HEADER info within those. Eg:

<obj>
    <header>
        <Prop01>val01</Prop01>
        <Prop02>val02</Prop02>
    </header>
    <line>
        <prop01>lineVal01</prop01>
        <prop02>ineVal02</prop02>
        <prop03>lineVal03</prop03>
        <prop04>lineVal04</prop04>
        <prop05>lineVal05</prop05>
    <line>
</obj>

What should I do in order to identify and use the very first record values within all the output objects?

Will I be able to read it into a java bean like,

<jb:bean beanId="header" class="org.me.Header" createOnElement="csv-set/csv-record[0]">

Any help is appreciated!!!

Thank you.

0

There are 0 answers