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

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


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.