csv2xml - The csv file format

There is no standard csv file format, different software applications have started using the file format and read/write csv files differently. Sometimes this is due to bugs in the software, and sometimes this is just to meet the needs of the particular application. Thankfully the majority of applications using csv follow the same standard, it is this standard which I will describe herein.

Back to homepage.

Basic structure

Here are the basic rules for formatting a csv file, then below will be some examples.

Examples

I believe the best way is to learn is by example, so here are some examples of valid csv files.

Example 1 -- Fairly average example

header1,header2,header2
my,cat,hat
fish,dog,cat
happy,fred,123

Example 2 -- Demonstrates escaping a comma

i went,  a cat,          fishing is bad, 12
a,       b,              c,              d
another, "example here", a,              b
"string with comma, is here", a, b,c

Example 3 -- Demonstrates escaping a charriage return

more complicated example, second field
"escape a CR in
this", second field
first field, second field

Example 4 -- How do you escape a " character

a,  c,            e
a,  "a,c,e",      e
a,  "fred""fish", e

Errata

Back to homepage.