3

Prologue

I've noticed that one benefit of using CSV over XML for data dumps is the fact that fewer disk space is used. See minimal working example below.

Let's suppose we have the following dataset. The representation in XML would be

<badges>
  <row Id="1" UserId="12" Name="Informed" Date="2014-09-23T18:03:54.633" Class="3" TagBased="False" />
  <row Id="2" UserId="7" Name="Informed" Date="2014-09-23T19:18:03.113" Class="3" TagBased="False" />
  <row Id="3" UserId="45" Name="Informed" Date="2014-09-23T20:16:45.523" Class="3" TagBased="False" />
  <row Id="4" UserId="25" Name="Informed" Date="2014-09-23T20:56:02.380" Class="3" TagBased="False" />
</badges>

The representation of that same dataset in CSV would be

Id,UserId,Name,Date,Class,TagBased
1,12,Informed,2014-09-23T18:03:54.633,3,False
2,7,Informed,2014-09-23T19:18:03.113,3,False
3,45,Informed,2014-09-23T20:16:45.523,3,False
4,25,Informed,2014-09-23T20:56:02.380,3,False

If we count the number of characters in each file, we get the following.

wc -m data.xml
wc -m data.csv
430 data.xml
218 data.csv

As we can see above, when using CSV, 212 fewer characters are used.

It is clear that fewer disk usage is an advantage of CSV files.

The question

What are some benefits of using XML over CSV files?

Additional information

I'm asking this because I would like to suggest the Stack Exchange data dumps are delivered as CSV files instead of XML files since that would imply that less bandwidth is used and fewer disk is used in the computers of people downloading this data dump (for the sake of the environment, people's time, and the use of the hard drive in people's computers), but first I wanted to make sure that I'm not missing an advantage of using XML files, that's why I created this question.

1 Answer 1

4

Four quick things that come to mind are:

  1. Relationships between entities (and the representation of a complex object) are more easily defined within the same XML file, whereas a CSV data dump usually contains just the data of a single Table.

  2. XML is arguably more readable than a flat CSV file.

  3. XML can be less error prone regarding unescaped special characters.

  4. XML can be used to preserve specific formatting of the data.

All that being said, when I worked with big data, CSV files were one of the common ways we'd deliver data to our customers. We never used XML. But I think on smaller databases, it's splitting hairs to debate over which format to use if the only concern is data size, since a 1 TB hard drive nowadays is the cost of a 1 GB hard drive 25 years ago.

Not the answer you're looking for? Browse other questions tagged or ask your own question.