<parameter>
<name>ApplicationName</name>
<value>WhizBang</value>
</parameter>
...
So that they could pass schema validation and still have some hope of extensibility.In the same way, if we receive a data transfer in XML and there is a schema, simple validation catches a lot of problems quickly. You'd be surprised how many times a company gives you a schema and then sends you xml which doesn't validate. In JSON, you have to write a program to get even basic validation.
Don't get me wrong: XML has problems, some inherited from html/sgml (entities!), and even more after serious abuse by consultants, archicture astronauts and enterprise vendors (SOAP! namespace overuse! 10 XML parsers in 1 app!). But it was also miles better than what came before and I feel the XML hatred pendulum has swung too far.
Today, JSON is in vogue, and I've seen enough IT to not swim against the tide. It is a reasonable solution for problems caused by XML abuse. Besides, there is value in going with the majority,even if it only fixes 80% of your problem. But I can only weep for the miserable date, numeric and comment support, and their endless stream of incompatible workarounds.
For your parameter example: You can't both strictly validate and have full freedom at the same time. Something has to give a bit. Some less horrible alternatives I've seen:
<parameter name="X" value="Y"/>
<subsystem name1="value1" name2=value2 ... /> , add newline for each attribute
<name>value</name>Edit: XML is just a proper subset of SGML by definition, hence it didn't introduce a single thing that wasn't there before. It only introduced XML-style empty elements and DTD-less markup, and SGML was extended in lockstep with XML to support these as well
XML is more than the part inherited from SGML, it's also the XML culture surrounding it. Namespaces are an example of something that created an XML dialect. And of course SOAP, which actually needs the WS-I standard to explain what parts of the WS-* standards to use or ignore, and how to interprete them. And even then 2 WS-I stacks will rarely interop without trouble. Lets not blame SGML for that monstrosity
<a:log /><b:log /><c:log />
can mean a math function, a text file that records what's happening, and a cut-off trunk of a tree and there will be no confusion whatsoever.(I really don't get how SOAP is relevant here.)
<element name="addressBook">
<zeroOrMore>
<element name="card">
<attribute name="name">
<text/>
</attribute>
<attribute name="email">
<text/>
</attribute>
</element>
</zeroOrMore>
</element>
http://www.relaxng.org/tutorial-20011203.htmlPlus there's a non-XML "compressed" version as well:
element addressBook {
element card {
element name { text },
element email { text }
}+
}
But I agree that XML like you posted is nasty, it's no harder to write <parameter name="ApplicationName">WhizBang</parameter>
instead if you need generic parameters, or <ApplicationName>WhizBang</ApplicationName>
if not.<parameter name="ApplicationName" value="WhizBang"/> ?
Your option is better, but XML is very (maybe too) flexible and is bound to be made a mess of.
ApplicationName=WhizBangJSON is great in terms of flexibility, but .INI files are really easy to read because everything is on the left side of the screen/window at all times.
For a general-purpose human-writable structured data format, I guess the ugly nonstandard hack that is "JSON with comments" is probably good. It's certainly faster to parse than YAML.
So when we have text with markup the text part is meant to be there for humans and the markup part is solely for computers. Now let's remove all text; now there's no content for humans at all, only for computers. How is this different from general-purpose data serialization?
(Some of the samples you give, like SVG, may not have any text content at all; it's basically a drawing language.)
Given that XML ecosystem has quite a few tools (e.g. several type description languages or a declarative data transformation language just to name a few) it's a very good general-purpose data serialization format.
As much as there is a lot to not like about YAML, it is the easiest one for humans to consistently write in my experience.
We don't judge Excel and Librecalc by how easy it is to open their files and produce valid spreadsheets without good tooling.
If they're working with structured data, why can't they use tools/editors which work with the structure, reveal it, and enforce it?
XML's incredible verbosity is a problem for computers too. I've spent time performance-tuning message parsing code that had no good reason to be slow except that our use of XML bloated the data and decoding time by an order of magnitude or more compared to a binary protocol with a schema.
I've gotten incredible speedups just by switching to SAX parsing in those cases.
I've been slowly ripping out YAML support and converting configurations to TOML.
Then there is floats without a leading zero. Missing colon after the key. And yea, naked keys. The need to wrap the entire file in { } or [ ] is just icing.
Honestly I feel the most bare simple conf format of [first-word] [rest-of-line] is enough for many programs that end up using but never taking advantage of more powerful formats.
JSON is often minified though - you're going to need something to use as a delimiter
Actually, I think you could leave out the delimiter altogether and still be syntactically unambiguous, since quotes are required around keys:
"key1":"value1""key2":2.75"key3":true"key4":"whatever"
though this looks terrible and there's probably some edge case I've forgotten. (Also it misses the point of JSON in that it's no longer valid JS. I don't know whether that's important anymore since you should be calling JSON.parse() not eval() anyway.)The one major reason I could see to use "JSON" as a conf file is in trusted node.js apps because you can then easily embed functions and logic in them if you need more advanced/customizable configurations. And you can do it with full syntax highlighting in your editor. And comments, and trailing commas, and naked keys.
Of course this is no longer JSON, it's straight up Javascript config files. But it has come in handy a few times when I want to override standard behavior on a per config basis, and most of the file is still just plain key: val
it's a shame json doesn't support them though. oh well. would be nice to restart the universe and get all this right next time. :-)
I think JSON is more efficient to write, but XML often ends up being more efficient to read due to comments and the fact that XML tags often give you better context. I think most programmers (myself included) tend to heavily optimize towards writability when we should think about readability a little more.
An example of this is ElasticSearch, where your queries are in JSON and often end up tons of levels deep - it is super easy to get lost in a sea of closing brackets, whereas XML would let you add comments in and the fact that closing tags have names in them would give you better context about what you were doing.
Not so much. Sexps don't provide a place hang "extra" information. It's been a pain point. While some lisps allowed decorating runtime things (eg objects with attributes, and symbols with property lists), their printed/readable representations were implementation dependent.
There's also a widespread misconception that Scheme is easy to parse. Numbers and all. It's actually very hard to get right. Real scheme parsers are quite large and hairy.
> XML was a complete and utter waste of time.
While XML was ghastly, there was an unmet need. There still is.
https://www.owasp.org/index.php/Top_10-2017_A4-XML_External_...