3 ms·
Millions of developers use XML all the time, it's called HTML. People can easily read and edit it with deeply nested structures, attributes, and even malformed
by manigandham 8y ago
Millions of developers use XML all the time, it's called HTML.
People can easily read and edit it with deeply nested structures, attributes, and even malformed data. Frontend frameworks using components and variations like JSX also maintain the same style because it's very natural to use.
Now try taking a typical HTML document and expressing it in JSON. Even an empty page would be completely unmanageable without tooling. People have a strange reaction when they hear "XML" but it's much more structured, usable, and widespread than you think.
- therein 8y agoI think the stigma comes from issues using XQuery etc. Not that they are unusable but they require adjusting your way of thinking.
- int_19h 8y agoBut XQuery (and XPath, being its subset) is pretty much just pure sequence comprehensions for the XML Data Model. It might have been unusual from a mainstream PL perspective back when it was introduced, but today, when C# has LINQ, and JS developers preach the miracles of map/filter/fold over immutable data structures, I don't think XQuery is all that exotic.
- manigandham 8y agoJSON has no querying system, it can only be accessed by deserializing to an in-memory object or using whatever custom APIs are available (like postgres json functions). JsonPath is the proposed standard, and it looks pretty much like XPath. And that's before getting into Json Schema.
- gridlockd 8y ago> Millions of developers use XML all the time, it's called HTML. HTML is not XML and even then few developers today use HTML without some sort of processing involved. HTML is also not a language used for configuration files, so it is really off-topic. The question is, do people prefer XML configuration over JSON configuration. The answer is that people generally prefer JSON. JSON just maps far better to data types we use in everyday programming. Have you seen some of the common ways of expressing key-value pairs in XML? It's horrible. > Now try taking a typical HTML document and expressing it in JSON. That's not the problem anybody is trying to solve here. We're talking about configuration files, not complex documents. But let's say I wanted to solve that problem, the representation would look like this: http://www.jsonml.org/ http://www.jsonml.org/ Not that bad at all.
- joezydeco 8y agoWell put. Thank you. In my world, config files are machine-parsed but human-generated and modified. JSON is just easier to work with.
- manigandham 8y agoIt's a technical distinction without a practical difference. They are both declarative languages to describe data. Why is it so horrible? Have you ever typed a <ul><li> list? Or <input name="key" value="value">? What exactly is so difficult about this syntax in XML but completely fine in HTML? The point isn't whether you can represent a document in JSON, it's about how easy it is for a human to manage it. The XML/HTML structure is far easier as things get more complex. The page you linked to shows this quite clearly even with the small "Bulleted List Example" at the bottom.
- SllX 8y agoHTML is distinctly not XML. There is XHTML if you want to use a form of HTML that is processed like XML, but XML processing is a lot stricter than HTML processing in which you can take a lot more liberties in the markup and still end up with a readable result, maybe even what you intended, whereas an XML processor will usually refuse to render incorrect XML markup at all.
- bauerd 8y ago>They are both declarative languages to describe data. This still applies then
- manigandham 8y agoI'm comparing the data structure and editing ergonomics (which are identical) between XML and HTML, not how they are processed. It's good for config files to have precise parsing instead of tolerating errors.
- gridlockd 8y ago> It's a technical distinction without a practical difference. There's a lot of practical differences when actually implementing configuration with either XML or JSON, due to technical distinctions. > The point isn't whether you can represent a document in JSON, it's about how easy it is for a human to manage it. If XML is easier to manage, why are people shifting from XML and to JSON for configuration? You may have some experience with HTML, but have you actually used some of these XML abominations that are used for configuration? > The XML/HTML structure is far easier as things get more complex. Configuration files shouldn't be complex. They're mostly key-value pairs, perhaps a couple of lists here and there and a modest amount of nesting. XML is complex to begin with. Perhaps at some stage, for some use-cases, XML starts becoming simpler to edit. Configuration files generally isn't one of them. > The page you linked to shows this quite clearly even with the small "Bulleted List Example" at the bottom. It's an example of representing XML-like structure with JSON, which is fairly easy. Try it the other way around, things get hairy. If you were to represent the data as JSON, you wouldn't write it like that.
- deleted 8y ago[deleted]
- josephg 8y agoI think using the popularity of HTML (a rich text format) to justify using XML as a configuration format is a bit disingenuous. The two use cases (structured data and rich text) are genuinely very different from each other. In rich text, the primitives are text and markup. In structured data, the primitives are structures (lists, maps) and data (strings, bools, numbers). The impedance mismatch goes both ways - try taking a typical JSON document and expressing it in XML. Which parts end up as attributes? Elements? Text nodes? How do you express the semantic difference between a list and a map? A string and a boolean value? It’s arbitrary, ugly and verbose no matter how you slice it. And, just like it’s inverse, basically unmanageable without tooling. Also HTML is not XML. HTML is non-strict (the spec is it’s parser not its format). HTML doesn’t have schema files. HTML doesn’t understand self-closing tags. HTML does have void elements (img, br, input, etc). HTML is designed for humans to write. And it’s a tool fit for its purpose, unlike the abomination that is XML.
- manigandham 8y agoAnother commenter linked to this: http://www.jsonml.org/ http://www.jsonml.org/ Scroll down and I think it shows it perfectly how (X|HT)ML tags are much simpler than JSON syntax once things get complex and nested. It's not that hard to define basic primitives like we do with HTML (which has dozens of tags) but XML also lets you define your own schema if necessary to make things more compact. I understand the technicalities between HTML vs XML but I don't see how it makes any practical difference when you're editing a bunch of tags in a text file. It's the same thing. The structure looks identical. What is the actual issue that makes HTML easy but XML hard?
- mlazos 8y agoThis is such a contrived example, they take html and show the equivalent conversion in json with the same schema. The point is in a configuration file you can remove nearly all the cruft of xml, instead of having <input “key”=key “value”=value> you don’t need any brackets or extra info. You just type { key:value } and you’re done. As many times as you want. I’ve had to hand edit complex msbuild configurations (xml based) in past projects and I can tell you lists and maps are hell. We’ve since converted them to yaml (another discussion), but the point is xml is terrible for human editing.
- benbristow 8y agoXML is a lot less pleasurable to parse from a programming point of view though. With a JSON file it's something like: const config = require('config.json'); console.log(config.apiKey); With XML you often have to use things like XPATH etc. to extract the data which is a lot more effort.
- manigandham 8y agoJavascript isn't the only language though. There are lots of XML and JSON parsers and serializers available to convert to an in-memory object. Most relational databases have great XML support too. I don't think people realize that JSON doesn't actually have a querying system at all, you have to deserialize it to an object to use. There is the coming JsonPath standard but that's not well supported yet and is pretty much the same as XPath.
- benbristow 8y agoI think JSON is just universally more easy to use. Every language I’ve used with it is mainly the same in the way it works. JavaScript, Ruby, Python, Perl, PHP... But you’re not wrong. Yes you have to deserialise it. Hence it being an Object Notation system. While you say JSON is trying to catch up with XML in regards to XPath, JSON is trying to catch up to XML with things like JSON Schema.
- pingec 8y ago> While you say JSON is trying to catch up with XML in regards to XPath, JSON is trying to catch up to XML with things like JSON Schema. Absolutely. I would say XSD is the strongest advantage of XML over JSON right now. XSD still has many things to improve but JSON schema is even further behind.
- gridlockd 8y ago> I don't think people realize that JSON doesn't actually have a querying system at all, you have to deserialize it to an object to use. You don't have to deserialize it to an object, you just do that because it's convenient in Javascript (and other dynamic language). It's a feature. Now try using XML like an object, what do you get? A DOM. Which is fine if you wanted a DOM, but I don't want a DOM. I don't need XPath or any of that stuff. These are tools to deal with the complexity of XML, which I don't have, because I am using JSON.
- doyoulikeworms 8y agoFair, but many developers are intimately aware of the shape of that kind of XML. Ever tried making sense of an XML document that tries to express something as complex as a web page, but without the requisite domain knowledge? It's painful. Slightly less so as a JSON document, IMHO.
- ttty 8y agoI never write html directly. With jsx you can have variables and reuse code.