Hacker News new | ask | show | jobs
by nonlogical 727 days ago
Out of curiosity, what are your top reasons to pick XML over JSON(+jsonschema) or Msgpack/Protobuf, as data interchange? I have come of age as a professional software engineer around the time when industry has started switching from XML to JSON, and as a consequence in the JSON camp, but I am always curious to hear out folks with a different opinion.
4 comments

Not OP:

I'm in the same boat, but I found XML has some nice properties that I sometimes miss in JSON, given that XML is used well ("correctly"), such as the differentiation of metadata (attributes) and data (nodes), namespaces, standard query languages, XSLT etc. (You can use XSLT on the web even.)

Think of all the custom, ad-hoc code that turns JSON into HTML vs having a declarative standardized way of doing so.

https://developer.mozilla.org/en-US/docs/Web/XSLT

When to use XML/What XML is good at: https://news.ycombinator.com/item?id=11446984
Great writeup. To add an example, I personally use JSON for most of my work, but have found myself using XML for certain AI use cases that require annotating an original text.

For example, if I wanted an AI to help me highlight to the user where in a body of text I mentioned AI, I might have it return something like:

<text>Great writeup. To add an example, I personally use JSON for most of my work, but have found myself using XML for certain <ai-mention>AI</ai-mention> use cases that require annotating an original text with segments.</text>

Msgpack is broadly fine (I shipped a parser for it a while ago, relatively few ambiguities in the spec). Json is kind of ok if you don't do numbers but schemas for it are a pain and the tooling gives me hacked together vibes.

I like being able to read and edit the data files easily in a text editor (bias against the binary formats) and for there to be a decent chance tools written by other people will interact predictably with the format (so it can't be bespoke).

I'd say the main feature is that an XML document with a schema tells you a lot about the various shapes of the file that you might need to worry about. It's essentially an extensible type system for tree shaped data.

XML has an annoying collection of spurious limitations but that's what you get with lowest common denominator / popular-cos-old systems.

Have you tried CBOR/CDDL tooling, nonlogical? What is your opinion of it?