4 ms·
I came up with an idea for a CSV replacement that's half-joke, half-serious. It's called XML Separated Values (XSV). It's meant to be a 1:1 drop-in replacement
by mtdewcmu 11y ago
I came up with an idea for a CSV replacement that's half-joke, half-serious. It's called XML Separated Values (XSV). It's meant to be a 1:1 drop-in replacement for CSV. It solves the ambiguity and encoding issues of CSV by recycling XML's solutions. It has basically two tags: <c/> and <n/>, for comma and newline, respectively.
Unfortunately, it needs a root element to be valid XML, so wrap the document in <xsv></xsv>. Also, add an XML declaration.
Example:
<?xml version="1.0" encoding="UTF-8"?>
<xsv>one<c/>two<c/>three<n/>1<c/>2<c/>3<n/></xsv>
(Whitespace is passed-through, therefore it's significant.)
This solves the ambiguity problems of CSV without complicating CSV by introducing things like data types (I think the virtue of CSV is its simplicity), and it should be extremely simple to write parsers based on either SAX or DOM (, etc).
Also, the use of XML provides unobtrusive places to insert application-defined metadata, for example:
<xsv columns="3">
This remains backwards-compatible with parsers that ignore attributes.
- oneweekwonder 11y agoCSV is human readable, how readable is left to the data. XML tries to be human readable, but you will need knowledge of elements or "tags", meta data. JSONLines also tries to be human readable, imo it does a better job, compared to XML. But not until Excel of LibraOffice implement a JSONL, or XSV reader/writer. Will CSV be the de-facto multi standard.
- mtdewcmu 11y agoI agree that XSV is somewhat less human-readable than CSV. However, you can automatically convert XSV into more-readable CSV and back (assuming your flavor of CSV doesn't lose fidelity).
- collyw 11y agoIn my experience XML is easier to read than JSON. Guess it depends on the complxity of the structure.
- mtdewcmu 11y agoI think one predictor of readability is the ratio of markup to data. XML gives you some flexibility there, but XML-based formats tend to have very verbose markup, which overwhelms the data. To cut back on markup in XSV, I used self-closing tags for commas and newlines. It would have been more conventional to use something like <row><column>...</column></row>. That has some advantages, maybe, but it doubles the number of tags (and it introduces things that are not strictly 1:1 with CSV, which could lead to ambiguity).