4 ms·
XML is very much misunderstood and this article is not an exception. XML is a notational tool. A notational tool is a tool for a human to write something by ha
by Mikhail_Edoshin 3y ago
XML is very much misunderstood and this article is not an exception.
XML is a notational tool. A notational tool is a tool for a human to write something by hand and then process with a computer. The important part here is “by hand.” E.g. I’m processing a corpus of someone’s letters and see a phrase like “on Monday I saw him the last time” and I know that I need to mark “on Monday,” “I,” and “him” with references to a date and people I have inferred from elsewhere, and the only way I can do this is by hand, there is no automation. Yet once I place those references, I can mechanically index the corpus, which is my goal.
But writing a configuration file is the same task. Here again I am doing a thing that in the general case has to be done by a human, but the goal is to process the result mechanically.
All other uses of XML are a misuse. Yes, you can use it for data interchange, but it is similar to programmatically calling a third-party tool via a command line. Possible, but involves much overhead and is way less convenient than using that tool via a library. If the data are not generally composed by hand, then they should not be in XML. (But I would argue they should not be in JSON or YAML either; we do this mostly because we have no suitable tools.)
As a notational tool XML is actually rather good. Yes, it is verbose. You know what is not verbose? A special language you create for your special case. It will outperform any generic notation out there. If you decide to do that, then you will have to write a parser, process the text and get an abstract syntax tree. But note that XML is an abstract syntax tree. It is the intermediate result you get if you decide to solve your case in a perfect way. So maybe you could start with XML, get the syntax tree right, write the code to process it, and then see if you still want a parser.
On XML verbosity: what if we compared not the overall length, but the number of syntactic symbols?
<server id="a" ip="1.2.3.3" role="back" /> -- < "" "" ""/>
{"id": "a", "ip": "1.2.3.4", "role": "b"} -- {"":"","":"","":""}
I’ve extracted syntactic symbols on the right and you can see XML is much quieter.
On XML not being mappable to objects and arrays: it is straightforward if you remember that the data are supposed to be a syntax tree. They are indeed far from the final representation in the same way an arithmetic expression is far from the code that will evaluate it.
- eviks 3y agoHere is a quieter part <server id=a ip=1.2.3.3 role=back /> -- < /> why do you need quotes when you have nothing to quote (no whitespace etc)?