Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When and Why is XML preferable to CSV? [closed]

People also ask

When would you use CSV over XML?

CSV is considered a flat structure of data format. It is highly convenient because it requires fewer technical skills and you can access files of this format with most applications. Additionally, CSV is significantly smaller than XML, requiring less processing power.

Which is better XML or CSV?

CSV should only be used if you are sending huge amounts of data and if bandwidth is an issue. Today, XML should not be used as a data exchange format because it's better suited for document markups.

What are two advantages of using an XML file over a csv file?

XML is arguably more readable than a flat CSV file. XML can be less error prone regarding unescaped special characters. XML can be used to preserve specific formatting of the data.

What are CSV and XML files?

You can export data values to a comma-separated values (CSV) format or Extensible Markup Language (XML) file for import to another data set or use in an external system. You can also define or use export formats when exporting reference values.


Some strengths:

  • You can validate XML data against XSD
  • You can easily provide contracts (as XSD) to other parties that should either create/consume XML data, without literally describing them
  • You can have one to many relations in multi-levels in XML data representation
  • XML is arguably more readable than CSV
  • XML is natively supported by the .net framework

To name a few from the top of my head.


.csv files are good when your data is strictly tabular and you know its structure. As soon as you start having relationships between different levels of your data, xml tends to work better because relationships can be made obvious (even without schemas) just by nesting.


XML has become the default for its many benefits that lots of other people have already mentioned. So the question really becomes "When and Why is CSV preferable to XML?".

I feel CSV is preferable to XML when: - you are loading simple tabular data - you are in control of both the generation and consumption of the data file - the dataset is large

CSV is perfectly usable if the first 2 points are true, and has a performance benefit that becomes more significant the larger the dataset is.

I did a quick test loading ~8000 records each with 6 text fields. Loading and parsing the XML took ~8 seconds. Loading the CSV took less than 1 second.

The overhead of XML is worth it in a lot of cases, but when the stars align, CSV makes more sense.


CSV is useful when you just have a series of a values that relate to some piece of information and you know you will always store values for each field.

XML has the benefit of having self-describing data (tags) and having hierarchy - which gives you a lot more flexibility in the way that you store the data.