next
|
Subject: Dynamic CSV to XML Author: Martin Börlin Date: 03 Oct 2006 10:42 AM
|
Hi!
I work in a project where we need to convert CSV files (no format defined yet) to a given XML format.
The CSV will have to be dynamic (yes, I know: why don't you use XML, this is like inventing another XML clone...) and an idea to make them dynamic is to prefix each line and then use a "proper" line-oriented comma separated values for each line, based on the prefix. I.e. in my example below the line starting with "order" must have no other fields on that line, the line starting with "customer" must have 8 fields where field number 2 is a first name, field 3 is a last name etc. The "order" ends when a new "order" line is found.
Is it possible to define this using Stylus Studio, and if so; how? Any comments/suggestions about my 30-seconds-dynamic-CSV-fomat is appreciated!
regards
-Martin Börlin
CSV:
order
customer, Martin, Börlin, Tranebergsvägen 52, , Bromma,,
productADSL,1024, , 4620903
productMobile, 0703992050, work, secret, VoiceMail
productVoIp, 4620903
productMobile, 0703110017, home, ,
order
customer, Pia, Börlin, Tranebergsvägen 52, , Bromma,,
productADSL, 1024, , 4620903
productMobile, 0703992050, work, secret, VoiceMail
order
customer, Selma, Börlin, Tranebergsvägen 52, , Bromma,,
productVoIp, 4620903
corresponding XML:
<order>
<customer>
<firstName>Martin</firstName>
<lastName>Börlin</lastName>
<street>Tranebergsvägen 52</street>
<postalCode></postalCode>
<city>Bromma</city>
<region></region>
<country></country>
</customer>
<products>
<product>
<adsl>
<size>1024</size>
<someValue></someValue>
<number></number>
</adsl>
</product>
<product>
<mobile>
<msisdn>0703992050</msisdn>
<type>work</type>
<visability>secret</visability>
<extras>Voicemail</extras>
</mobile>
</product>
<product>
<voip>
<number>4620903</number>
</voip>
</product>
<product>
<mobile>
<msisdn>0703110017</msisdn>
<type>home</type>
<visability></visability>
<extras></extras>
</mobile>
</product>
</products>
</order>
<order>
<customer>
<firstName>Pia</firstName>
<lastName>Börlin</lastName>
<street>Tranebergsvägen 52</street>
<postalCode></postalCode>
<city>Bromma</city>
<region></region>
<country></country>
</customer>
<products>
<product>
<adsl>
<size>1024</size>
<someValue></someValue>
<number></number>
</adsl>
</product>
<product>
<mobile>
<msisdn>0703992050</msisdn>
<type>work</type>
<visability>secret</visability>
<extras>Voicemail</extras>
</mobile>
</product>
</products>
</order>
<order>
[etc...]
</order>
|
|