by JonChesterfield · 2y ago · 0 comments
Unhelpfully my only pain point with XML parsing is colleagues refusing to use XML in favour of json or, in really grim moments, yaml.
So I'm delighted to see a sensible modern web language implementation of the one true data exchange format. Thank you for sharing it.
XML is just terrible though. Unless you have a proper schema everything is entirely untyped (tbf the schema support is pretty good). But more to the point it just doesn't map to normal programming language objects cleanly. It's a document markup language, not an object encoding.
That means there's an annoying mismatch when parsing for 99% of use cases.
Couple that with the crazy verbosity and the weird confusing features like namespaces... I think I would rather use YAML to be honest, even though it is really bad.
Since YAML is a superset of JSON I sometimes actually use JSON with `#` comments, and read it as YAML. Only downside is nothing checks if you are using that format correctly.
I have seen real life examples of some developers putting money as a decimal in JSON, then other developers using some default parsing into float and finally truncate that float on conversion to Decimal money to loose 1 cent.
I have also seen examples of developers putting int64 random IDs in JSON interacting with Azure Cosmos, then discover that when fetching data back the numbers had been silently rounded to 53 bits! (i.e., float64 precision)
JSON does not document at all how its numbers should behave, making it useless for a lot of things.
Honestly prefer XML, being honest about not having typing.
Don't get me started on YAML and types..
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.
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>
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.