Search code examples
jsonxmlcsvsoapdata-transfer

Why is XML still used?


I was going through data transmission and was wondering why XML is still in use?

Every source puts JSON and even CSV data format over XML, but from practice I can say that XML is still popular. Only reason that comes to mind is SOAP and its WS-security, which allows only XML. But even though every REST API prefers JSON, XML can still can be used.


Solution

  • Because XML is a better fit for documents than JSON or CSV.

    Current use of XML for data (as opposed to documents) is a relic from an earlier era when XML's use had been over-extended beyond its natural fit as a representation for documents.

    Here are some useful current heuristics to guide your choice between CSV, XML, and JSON:

    Choose CSV if

    • Your data is tabular and you have to transfer it between relational databases or spreadsheets.

    Choose XML if

    • An industry standard XSD exists.
    • You value more mature validation standard and tools.
    • You need to transform the data to another XML form. (XSLT is excellent for transformations.)
    • Or, you have to represent mixed content (tags mixed within text).

    Choose JSON if

    • The closer fit to JavaScript is valuable to you or your callers.
    • You prefer a lighter-weight solution.
    • Or, the above Choose XML if reasons do not apply to you.