XML vs comma delimited text files

后端 未结 12 2658
面向向阳花
面向向阳花 2021-02-20 08:25

Ok, I\'ve read a couple books on XML and wrote programs to spit it out and what not. But here\'s the question. Both a comma delimited file and a XML file are \"human readable.

12条回答
  •  萌比男神i
    2021-02-20 09:16

    The fact that XML is human readable does not mean that has been made with the idea of having it read (or even edited) directly by humans.

    XML has a nice set of properties that make it a good choice for many cases, in particular when you have the human resources to deal with the additional burden that such properties inevitably bring in: validation, well defined standard, a lot of tools, a very flexible architecture, it maps nicely to a tree model, which is what many programs use. Its human readability is an added value that simplifies debugging (try to do debugging of a binary file...), inspection and small changes for trivial cases.

    CSV on the other hand is easy, quick and linear, although many dialects exist, and parsing it well is far from trivial (and with the added problem that it looks trivial!). For most applications involving table of data, CSV is the perfect choice.

    In general, however, there are cases of data representation you can solve with XML but you cannot solve with CSV (for example, a tree). On the other hand, any data that can be represented in CSV can also be represented in XML, although it's not guaranteed (and indeed is also verified) that it will be more efficient (in terms of space, ease of parsing etc). It's a matter of "degrees of freedom" of your format. XML has a higher value of degree of freedom. CSV is lower. The hype behind XML is also relative to this fact.

    Don't fall victim of the hammer syndrome: when you have a hammer (XML), everything looks like a nail (something that you have to solve with XML). Reality is much different and nuanced. XML is cool, but it's not the answer to any problem.

提交回复
热议问题