4 ms·
Very nice, thank you! 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
by JonChesterfield 2y ago
Very nice, thank you!
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.
- nonlogical 2y agoOut 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.
- 616c 2y agoHave you tried CBOR/CDDL tooling, nonlogical? What is your opinion of it?
- dgb23 2y agoNot 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 https://developer.mozilla.org/en-US/docs/Web/XSLT
- jerf 2y agoWhen to use XML/What XML is good at: https://news.ycombinator.com/item?id=11446984 https://news.ycombinator.com/item?id=11446984
- jtmarmon 2y agoGreat 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>
- JonChesterfield 2y agoMsgpack 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.
- IshKebab 2y agoI agree YAML is awful. JSON is ok if you allow comments at least (for configuration use cases). There are a couple of variants that do: JSON5 and Jsonnet. I like JSON5 for it's relative simplicity but Jsonnet has much better ecosystem support so I'd probably go with that. 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.
- dagss 2y agoJSON numbers have such huge issues that I would question that JSON has types either.. 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..