by cptskippy · 10y ago · 0 comments
I think it's bad reputation comes from anyone not using an enterprise language because the support just isn't there.
I recall working with a partner who we were doing an identity federation with. Our system was using WS-Trust which is a SOAP/XML protocol. It wasn't ideal but everyone seemed to support it ok. These guys were cutting edge though and used Ruby on Rails.
No support for the protocol wasn't a huge deal, just means you have to craft your XML for your SOAP calls yourself. But at the time we were doing this, RoR didn't have SOAP or XML libraries. They had to write everything from the ground up. It sucked for me and I was just fielding rudimentary questions, I can't imagine how painful it must have been for them.
On the contrary, I think that XML's bad reputation comes from the fact that it is <adverbial-particle modifies="#123">so</adverbial-particle> <adverb id="123">incredibly</adverb> <adjective>verbose</adjective>.
Also, the whole child/attribute dichotomy is a huge, huge mistake. I've been recently dealing with the XDG Menu Specification, and it contains a child/attribute design failure, one which would have been far less likely in a less-arcane format.
XML is not bad at making markup languages (and indeed, in those languages attributes make sense); it is poor at making data-transfer languages.
JSON has become popular because a lot of bad programmers saw nothing wrong with calling eval on untrusted input (before JSON.parse was available). It's still more verbose than a data transfer format should be, and people default to using unordered hashes instead of ordered key-value pairs, so it's not ideal.
The best human-readable data transfer format is probably canonical S-expressions; the best binary format would probably be ASN.1, were it not so incredibly arcane. As it is, maybe protobufs are a good binary compromise?
I have a system that has things like <Task ID="6">Blah</Task>. Why is the ID, clearly always an integer in every sample of hundreds I see, represented as a string?
Another favorite: <ExecuteCommand>[CDATA[Batchfile.bat]]</ExecuteCommand>, while a binary or something else will be <ExecuteCommand>"program.exe /argument:f /argument2:x"</ExecuteCommand>.
By the way, this is an enterprise as it gets: a software tool from a four-letter hardware company, quite huge, trying to sell off its software division. I wonder why.
XML is like all other "crap" tools: Java, PHP, SOAP: some people do not grok the spirit of the law, and they do weird things that reflect their discomfort and hurried need to operate with it. Many write it off.
I agree with your points, this is just my corrolary. The sad thing is SEXPR and XML are not far removed, one is arguably a subset of the other, and notice how people lose their shit when you ask them to consider Lisp languages for daily works because "all those parens are stupid" and how the culture surrounding a potentially viable tools makes people close up without delving in with curiosity.
Becase XML is a text-based markup. If you truly want binary data you need to encode it and use CDATA sections.
Why pretend it is a string at all?
<Task> <ID>3</ID> </Task>
I should have been more clear. Sometimes you have these argument type deals <Task ID="3"> where I would at least hope for <Task ID=3> or the monstrosity above (I assume ID=3 is not valid in hindsight, I am getting tired just writing this all on the second pass even!). And I see all different variations in the same XML file! There is no logical consistency, not even in the same config for the same function of this multi-stage system.
I am not even a novice programmer, and I find the variation annoying, and sometimes hard to reason about when I want to know what the hell the programer was thinking.
The valid part for the CDATA portion has changed several times in minor releases, so when our server team upgrades, I get to figure out the new syntax.
I thought XML was proposed to avoid these things! Haha. Again, tools in the hands of "wise men" like me are dangerous. I am probably as ignorant as them, I just think I know better!
You're really asking a different question here: "Why should an integer be used as a task ID?" Storing the task ID as a string may give you options in the future that you wouldn't otherwise have, at a relatively small cost in parsing performance and validation overhead.
Most of the world's regrettable XML schemas were faulty at the specification stage, not the implementation stage. To minimize the likelihood of eventual regret, I usually prefer to store stuff in strings unless there's a very good reason not to. The fact that I'm using XML means that I'm not that concerned about performance, so... strings, it is.
A similar argument can be applied to the child/attribute dilemma. If there's even the slightest chance that a field isn't always going to be a leaf node, I'll do the extra typing and make it a child. Ideally the parser would be written to make them both work the same anyway.
Disagree. JSON became popular because it was extremely easy to implement (both for marshaling and consuming), and because it was extremely lightweight.
I think you could also make the argument that JSON was conceptually easier for programmers to wrap their minds around. You could just pretty-print it and quickly get an idea for the object's format, attributes, etc.
Look how short the standard is: http://www.ecma-international.org/publications/files/ECMA-ST... It's small and perfect, like a 2x1 LEGO block.
Here's the XML spec: https://www.w3.org/TR/REC-xml/ <backs away slowly>
E.g.
{"name":"John","age":42}
vs. <person name="John" age="42" />A canonical S-expression parser is strictly easier to implement, given that S-expressions consist only of lists and byte sequences (no numbers or objects), and is even more lightweight. JSON's big advantage was that it was familiar to a JavaScript programmer, that's all.
XML is actually IMO not that bad at human readability, it's pretty good. It's terrible at human writability. Conversely S-exps are lovely to work with.
<a>12<b>34<c>56<d>78<e>90</e></d></c></b></a>
Appending something to the end of the d element is easy, since one can just search for its end tag. In JSON and other formats that only have one single character at the end, one has to count brackets or parentheses for this purpose: (12(34(56(78(90)))))JSON solves this with indentation, pretty printing, and using paired symbols that most conpetent editors can automatically balance. This solves the homogeneous case too.
Incidentally, XML can benefit from the first two, and many editors balance tags, so you can get the same thing there.
> Also, the whole child/attribute dichotomy is a huge, huge mistake.
Those two factors run counter to each other. Attributes decrease verbosity, compared to child elements.
I agree, though. A few changes would make XML closer to ideal: eliminate attributes and eliminate the name in closing tags (<tagname>value</>), which makes child elements much less verbose, and reduces the need for attributes.
Then just change '<tagname>' to '(tagname,' and '</>' to ')' and you'll have S-expressions.
Consider this:
(feed
(version 1)
(title "Example Feed")
(link http://example.org/)
(updated "2003-12-13T18:30:02Z")
(author (name "John Doe"))
(id urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6)
(entry
(title "Atom-Powered Robots Run Amok")
(link http://example.org/2003/12/13/atom03)
(id urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a)
(updated "2003-12-13T18:30:02Z")
(summary "Some text.")))
That is a canonical S-expression (for a Scheme or Common Lisp reader, just quote the URIs too) version of: <?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Example Feed</title>
<link href="http://example.org/"/>
<updated>2003-12-13T18:30:02Z</updated>
<author>
<name>John Doe</name>
</author>
<id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
<entry>
<title>Atom-Powered Robots Run Amok</title>
<link href="http://example.org/2003/12/13/atom03"/>
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
<updated>2003-12-13T18:30:02Z</updated>
<summary>Some text.</summary>
</entry>
</feed>
I particularly like how URIs are sometimes encoded as attributes and sometimes as child text elements.And compare to your proposed version:
<feed>
<title>Example Feed</>
<link>http://example.org/</>
<updated>2003-12-13T18:30:02Z</>
<author>
<name>John Doe</>
</>
<id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</>
<entry>
<title>Atom-Powered Robots Run Amok</>
<link>http://example.org/2003/12/13/atom03</>
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</>
<updated>2003-12-13T18:30:02Z</>
<summary>Some text.</>
</>
</>
I think it's pretty clear which is the most readable and elegant. <feed>
<title>Example Feed</>
<link>http://example.org/</>
<updated>2003-12-13T18:30:02Z</>
<author><name>John Doe</></>
<id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</>
<entry>
<title>Atom-Powered Robots Run Amok</>
<link>http://example.org/2003/12/13/atom03</>
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</>
<updated>2003-12-13T18:30:02Z</>
<summary>Some text.</>
</>
</>
That said, I like S-expressions too, and I wish more parsers and tools existed for them, such as schemas, query tools, and simple transformation tools.I think the distinction here is that the one is an identifier which is not intended to be dereferencable, and the other is a link to a resource which has to be retrievable. In the good old days the id would most likely have been a URN and the link a URL, but that distinction was being discouraged in favour of the more general URI term at the time the Atom spec was developed. [1]
So while they're syntactically both URIs (well technically IRIs), they're functionally quite different. It may be debatable whether that's a good enough reason for the one to be an element value and the other an attribute value, but I don't think that decision was obviously wrong.
How would you include an HTML summary, for example?
Child and attribute "dichotomy" is not a mistake. What you mean is that these two samples appear to be equivalent:
<foo value="123" />
<foo>123</foo>
But they are not equivalent. The first line (with an attribute) is there solely for the computer. When the document is rendered, the human user is not supposed to see anything there unless the computer adds it.The second line (with text content) is there for both the computer and the human user. The text "123" is for the human user; the fact that this text is something called "foo" is for the computer. When the document is rendered, the human user will see "123" here. Maybe computer will enhance something or maybe it will just use it as index or reference, whatever.
Most people who don't like XML seem to only encounter it in config files. In config files there's normally no content that needs to be there for the end users, so all data can happily go into attributes. The text content starts to matter when we deal with natural language texts.
Which seems pretty wasteful.
> Child and attribute "dichotomy" is not a mistake.
It's not for a markup format — as I mentioned, it can make sense there — but, as you mentioned, it doesn't make sense in a config or data file format.
S-expressions are good if you work with Lisp like languages, but I don't think they're very readable if you're not into Lisp. I also can't see how they map easily into datastructures of imperative programming languages or even statically typed functional programming languages like haskell.
Take a look at https://news.ycombinator.com/item?id=12198581; I think it demonstrates how readable one dialect of S-expressions can be.
> I also can't see how they map easily into datastructures of imperative programming languages
JSON consists of numbers, strings, booleans, objects and arrays; canonical S-expressions consist of bytes and lists. I contend that one can easily encode strings, numbers and booleans alike as bytes, and both objects and arrays as lists. Consider:
{
"id": 1234,
"isEnabled": true,
"props": ["abc", 123, false],
}
This could be encoded in canonical S-expressions as: (object
(id "1234")
(is-enabled "true")
(props (abc "123" "false")))
Granted, one still must convert the strings "1234," "true," "123," and "false" into the expected types, but with JSON one still must check the expected types anyway; it's not that big a difference.And I honestly think that the S-expression version is far more attractive.
{object: [
{id: "1234"},
{isEnabled: "true"},
{props: ["abc", "123", "false"]}]}
Not quite the same, but nothing keeps you from parsing an array of key/value pairs instead of a hash.I personally think TOML is a bit more readable...
As a result, in my experience, JSON tends to be more robust in real world use - even when a schema is available.
Let's say we have a dog who has four paws. In XML:
<dog>
<paw health="ok">
<paw health="ok">
<paw health="ok">
<paw health="ok">
</dog>
In JSON: { "paws": [
{ "health": "ok" },
{ "health": "ok" },
{ "health": "ok" },
{ "health": "ok" },
] }
I think what the GP is getting at is that JSON is always describing the relationships between a thing and another thing, rarely the things themselves. In the JSON version, for example, it can be assumed that an object in the "paws" array is a paw.This example is sort of a straw man. The JSON version could be wrapped with { "dog": {...} } and the individual XML paws could be wrapped in a <paws> element. But in any case, JSON doesn't need you to give an explicitly label the type of each paw, just what they belong to and what's known about them.
All trees are graphs. Not all graphs are trees; there could be cycles, or children with multiple parents in an arbitrary graph.
In JSON, the nodes are literals: numbers, strings, booleans, arrays, hashes (object constructors). The edges are hash keys (object field names in the constructors).
In XML, the nodes themselves have the names. The edges are implicit in the syntax via containment, and are unlabeled.
In programming languages, generally our values don't have names. Instead, our variables have names, and refer to values; variables can be assigned different values, but the name doesn't change. More physically, if the values are stored on the heap, variables are pointers to values on the heap, and fields of heap objects are further pointers to more values on the heap. Here, variables and fields are edges, and the values are the nodes. Looked at from a graph theory perspective, the in-memory model is an edge labeled graph.
When Savon came out 6-7 years ago it was a huge relief. Luckily, by that point, I was seeing a lot less SOAP. But even with Savon, the experience was only lifted to "not awful", never to "wow, I'm glad they used SOAP, this is so easy."
[1] I think it might have been http://www.yoshidam.net/Ruby.html#xmlparser
I think this alone should be enough to cast doubt on it, based on my (albeit limited) interactions with "enterprise" software.
>I think it's bad reputation comes from anyone not using an enterprise language because the support just isn't there.
What, like JavaScript? I've had to read and write XML packets from a Node app to work with (surprise!) an enterprise app. I had probably 20 choices of libraries with varying levels of features, and the one I chose worked fine.
I was lucky, compared to some of the others on this page: The "RPC"-style XML commands and responses I had to parse and generate were all well standardized, so I just wrote a wrapper that extracted the completely opaque tree of XML into a flatter JavaScript object/hash that was really easy to deal with, and similarly made a wrapper that would trivially generate the monstrous XML required to send commands and responses back to the server. My JSON-equivalent objects were easier to manipulate (and would also have been easier to deal with in Java or, in this case, C#), equally rich in the information they carried, but could have been serialized with 1/3 the number of bytes per message. Totally a win-win-win.
What I don't understand is why anyone thought using XML that way was a good idea, and why it still is popular in the enterprise. Bad habits are hard to break, I guess.
Namespaces, which then gives you easy answers for Internationalisation (xml:lang), a subject-predicate-object data structure (RDF), which can lead on to logical meaning/modelling of data (RDFS/OWL), which then lets you look at harder questions like trust/provenance.
There's also schema validation (XSD), transformation (XSLT), which then provides you tools like XPath.
Most of that is on the front page for the technology: https://www.w3.org/standards/xml/
The real problem is not syntax, its communication between groups with differing experiences and interests - how do I know your messages mean the same thing as what my system expects?
If you prove to be malicious, do I have to write a strict validator before I trust your input?
If you want to ensure your messages are well formed before they are sent, do you also have to write a validator?
How do I know our validators are checking the same things?
If you want to send a large document oriented data structure, but I only care about a specific section relating to my interests; do I have to understand where to look and what all of the surrounding material is; or can I query for the relevant bits?
On the more complicated RDF side of things - if you want to share identifiers with me, how do we both avoid calling everything record id=1?
If we are both talking about the same thing but know different parts of the story, how can I recognize your information as describing the same thing I know about?
If we both know about the same Thing, and know certain logical facts about that Thing, can we check those facts actually make sense against shared rules?
If we both know about the same Thing, and can see a logical inconsistency in data, can we reason about which data to Trust and why?
Unfortunately, communicating properly is hard even with all of the tools to help.
We tend to opt towards subjecting systems to an ongoing fuzzing test because we don't value many of the above things - we tend to work in organisations with a short attention span focused on the now and a narrow set of interests. It just kind of works for the 80% of the time, so we move on.
Contrast that with something like a library or museum, and you see why ideas like Dublin Core really catch on there.
XML is designed to be a markup language. The fact that it has all of these other things bolted on doesn't actually make it a good generic data interchange format.
For things like RDF, maybe it's the best option we have, but that's not because XML is great, it's because XML was used in the only standardized option.
Looking at an example of xml:lang:
<?xml version="1.0" encoding="utf-8" ?>
<doc xml:lang="en">
<list title="Titre en français" xml:lang="fr">
<p>Texte en français.</p>
<p xml:lang="fr-ca">Texte en québécquois.</p>
<p xml:lang="en">Second text in English.</p>
</list>
<p>Text in English.</p>
</doc>
...this is a nightmare. If I want to translate a document, the last thing I want to do is embed each translation inline like that. Almost certainly the best response is to "fork" the document at the highest level and include separate language versions of the document; otherwise, if you have 20 translations of the document, you need 20x the text in the document than any one reader will need.Yes, XML gives you that particular hammer. But using XML results in a lot of sore thumbs.
Schema validation is nice to be sure. I'm using JSON Schema Validation myself [1] to verify incoming JSON, and I'm automatically generating those schemas from the TypeScript data structure specifications [2]. This is particularly good for a JavaScript language target, of course, but I find XML and XPath to be ugly or painfully slow in every language I've used it from, while JSON just has a better impedance match to data storage and interchange.
No, JavaScript is not what I'd consider an enterprise language. I'm talking about C++, C#, VB.NET, Java, and LotusScript. Enterprise languages and enterprise applications (e.g. Siebel) have no problem talking to each other via SOAP/XML and they all produce WSDLs that are easily consumed by one another.
When using something like C# or Java you can easily import a WSDL from another application and the toolchain will automatically generate all of objects defined and properly serialize/deserialize XML into those objects. There's no need to write parsers or use sockets/webclients to talk SOAP.
Newer backend languages and frameworks (e.g. RoR, NodeJS, etc) don't have these mature and robust toolchains for XML/SOAP.
To illustrate: Protocol Buffers' wire format is much more compact. It removes the complexity of having to deal with XML parsers by providing classes generated from the message definition/schema. You can use it with GRPC to implement your service APIs. It is supported for many different languages, including Java and C#. It now even has a JSON mapping [2]. Overall, Protocol Buffers can do everything XML can do as both an exchange format and as a configuration language but better.
[1] https://developers.google.com/protocol-buffers/
[2] https://developers.google.com/protocol-buffers/docs/proto3#j...
If your organization values the existence of a standard over technical excellence, then there is no use in convincing you. Otherwise, in terms of ease of use, performance, tooling, and human readability and writability, Protocol Buffers is superior to XML-based protocols (since the API for converting between the binary and text formats is extremely simple to use).
As a fun fact, if you really wanted to use XML as a wire format, you could even write an XmlFormat ser/de for Protocol Buffers, similar to the JsonFormat that is already provided, but then it would defeat one of the main purposes of using Protocol Buffers in the first place because you would replace an extremely performant wire format with an extremely sub-optimal one.
With a language like Ruby, PHP, etc that isn't strongly typed it's not nearly as big of a deal. Developers in those languages are used to assuming everything is a string and converting it to something useful without the need to premap every datatype.
That's probably the main reason that XML was so much more popular with the languages you mention compared to the parts of the ecosystem that didn't benefit from it's constructs much (if at all).
So I was figuring out the Java XML stuff (don't remember what that was exactly, probably standard). But at some point the timeout in my brain kicked in, and I just wrote a loop generating the XML by brute-force through PrintWriter or something. I even escaped strings right since some library I had available conveniently offered the escape method (Guava maybe?).