Hacker News new | ask | show | jobs
by hackrmn 27 days ago
Every time XML comes up, I feel obligated to share my opinion (I too wrote XML a the turn of the millennium and have seen it become and still witness on occasion it being excommunicated).

XML is verbose and therefore uglier than it ought to be. I think most of the haters hate it for that alone -- there's not much else to hate because you don't have to deal with the rest, it's not really imposed on you unless you really have to deal with someone else's XML application.

What do I mean? Well, the brackets thing and the necessity to repeat name of every element twice, in correct (LIFO, last in first out) order, isn't great, admittedly.

What XML has that the dev-bro alternatives that have flooded the void XML left since, haven't gotten and thus see being reinvented, are: namespaces, attributes and interop using the former two. Sure you can write JSON and YAML (the latter deservingly being incredibly hard to parse correctly -- they tried to design a better XML but failed IMO) -- but these suck as meta-languages because there's not much "meta" there. JSON, for example, allows you create properties and has a few types (kind of more than XML, really) but it leaves semantics up to you and namespaces are up to you to re-invent, poorly. If you think I am stretching the argument, see if you can represent an HTML document (no, not Markdown) with a JSON file.

YAML is a similar story, albeit with a few cool things like aliases. I think it's a better attempt to give the world a better XML, but the jury is still out on that one.

The killer thing with XML, for better and for worse, was plethora of tools to work with it. I wrote a fair share of XSLT documents to transform data, back when there was momentum in XHTML, for example. XSLT barely supports JSON and it's not pretty. XPath cannot natively understand YAML -- unless you convert it to XML which I guess re-animates XML as some sort of Frankenstein's monster. And even if it were a [pretty] monster, dealing with intermediate representation for the kind of purpose, is a can of worms all of its own.

Ironically nobody seems to hate HTML 5, seemingly. Or React basically turned it into a greasy cogwheel nobody needs to look at. Because if you look at it, it's in my opinion an abomination even compared to XML (unpopular opinion) -- the parser is quirky and behaviour is defined by the standard per element type (i.e. some elements need a closing tag and some do not, and what happens if you forget a closing tag is element-specific; care to remember the set of rules to ensure your document renders to your liking?). It has no namespaces but it has "custom elements" which require a dash in the name as poor' man's namespaces and you can't omit one, and now we have a Web of `x-spinner` and `x-carousel` because it turns out everyone rightfully wanted default namespace but didn't get one. Anyway, it's all plumbing, right -- the idea of _writing_ HTML has largely come and gone us by. And I am digressing.

4 comments

The one good feature of HTML 5 was the introduction of boolean attributes. It's a feature XML could and should adopt.

The whole handling of custom elements was fumbled beyond belief. The HTML spec is a disaster particularly it's parsing rules the complexity of which is used as excuse by HTML spec authors not to improve the language.

XHTML was a better path.

I think the reason we don't see too many people complaining about HTML 5 is because not many web programmers use it directly, most are using JSX.

I agree we shouldn't have thrown the baby out with the bathwater -- and it's not like _strictness_ was not in XML's spirit, so your usual suspects for primitive types -- numbers and booleans, to name a few -- _could_ have been an improvement along the XML's path of evolution. But something tells me that these features only open a door to more features that are needed. The bounds on what constitutes the [sufficient] set of fundamental types, is a hard problem to solve, especially if it cannot be extended through itself (composite/compound types). XML had not anything but strings for attribute type, but that also made it simple and kept it away from the domain of type theory and parsing more than it already had to have parsed. So I am undecided, but I liked the "one good feature of HTML 5" part of your comment, so I took your bait ;-)

XHTML, as has been _repeatedly_ mentioned by multiple people -- a thing that comes again and again -- at least was _strict_ in that your malformed document told you _early_ (or, rather, a compliant XML user agent did, like your Web browser), where with HTML it's your users that find out, except they have no clue what's going on -- they know even less about HTML 5 parser than the author does, staring at something that should have been a list item but becomes a table cell element or some such.

If HTML 5 is indeed not even used directly, that makes the argument for the _stricter_ format like XML-based XHTML even more attractive -- machines do much better with strict bounds than humans do, so if humans aren't writing HTML, then it feels like we've been sold on the wrong premise, even if retrospectively.

Boolean attributes are less about types and more about syntax convenience IMO, even HTML treats them as empty strings. <tag attr> is a shorthand for <tag attr="">, which then in your program you can decide if some attributes should handle empty strings as a truethy value. Some cases like <person name> the program would still make sense to treat it as an empty string.

> If HTML 5 is indeed not even used directly, that makes the argument for the _stricter_ format like XML-based XHTML even more attractive

True however those who control the HTML spec are unlikely to let it go. Since XHTML has been treated as effectively deprecated some feature like incremental document streaming do not work in XHTML, this makes it unlikely for libraries that abstract away HTML to adopt XHTML as a target.

Right, if what you mean is making the `=""` optional, then it seems even more attractive than types, I admit. You'd have to amend the XML grammar to see if making the `=""` optional introduces problematic (for e.g. the reference parser) ambiguities that weren't there before. From the looks of it / intuitively it doesn't seem to be the case, but with a language that's deployed in a gazillion places such small changes rightfully warrant new major revision, which would be XML 2, I guess. Which would have wide ramifications, I imagine. Which brings me to W3C....

> True however those who control the HTML spec are unlikely to let it go.

Like I said in another comment, I believe XHTML was axed because it stepped on _someone_'s toes. I suspect it had to do with W3C being understaffed and criticised for being too slow at the time -- by most of the industry, and most of it deservingly -- and WHATWG (with Google co-authoring their standards) stepping in as the authority on all things Web, and somewhere between the two XHTML was used as the proverbial fall guy. Speculation, of course -- but a lot of good, useful work was thrown out the window with XHTML. Not the first time it happens, of course, but this was the Web we're talking about, not Adobe's product portfolio.

I've heard the "streaming" argument before, by the way -- it keeps being mentioned (probably because it was one of the official reasons for the transition to HTML 5), but I think it's a "ruse" -- nothing about XHTML in practice prohibits an agent from progressively rendering an XHTML document, and if something really did, in W3C's writing for instance, then all they needed to do is relax that requirement because again -- there's plenty of hierarchical data formats with strict rules that by their very nature don't preclude parsing (or semantic analysis / rendering) done in streaming fashion.

I don't like HTML5 and to this day I don't understand what was actually gained by dropping XHTML.
XHTML was dropped because it wasn’t backwards compatible, and it was too strict in its syntax. Minor syntax errors that could be automatically corrected by the browser turned into full page errors.
Can you think of a minor syntax error example that you believe should be corrected by the browser, and better than the author would (had the Web browser notified them early -- by aborting rendering as was the case with XML)?

There's a bit of irony with the fact that HTML 4 which _did_ have browser "correct" errors (albeit in non-standardised manner) _was_ what motivated XML in the first place -- it's just that in light of the wildly different correction behaviour between Netscape Navigator, Internet Explorer, etc, they decided on a pragmatic solution -- abort and tell author, like a C/C++ compiler. The latter can also correct syntax errors, strictly speaking -- but you'd be hard pressed to find a programmer that would seriously consider letting the compiler do that. Why HTML should be different?

Say you forgot a `</p>` and then comes a `<li>` -- since `li` elements cannot be children of paragraph elements, I guess the Web browser, in compliance with HTML 5 for example, could mandate that the paragraph ends just before the `<li>`, meaning it behaves as if there _was_ a `</p>` before the former, _and_ also inserts... what, a `<ul>`? Why not `ol`, then? This heuristics is messy, if only because the Web browser doesn't have enough context to _know_ what the author wants, and can't assume a single kind of omission. And HTML 5 simply defines some default behaviour, handwaving the problem, but the truth is no HTML 5 authors -- myself included (I have been writing HTML in one [proto-]form or another since 1994) -- ever remember what those rules _are_.

Meanwhile valid XHTML like having custom elements as table children, in HTML gets silently "corrected" to an malformed document.

I'd much rather have the stricter syntax parsing of XML, vs the complex and outdated structural correction rules of HTML.

I think this is _the_ most popular criticism of HTML 5 vs. XML, that I have seen mentioned. Which is telling, quite frankly. It makes me think that the powers that be that pushed HTML 5 really had a different agenda than what they purported to have. We might never know the politics behind it, but I struggle to comprehend the wisdom of a decision to basically overhaul the lingua de franca of the Web because "XML parsing is hard!" then replacing it with HTML 5 and its peculiar "context sensitive grammar" noone ever remembers or bothers to look up, and the other features like custom elements (with the latter, by the way, in the spirit of "let's just ship it and see", they kind of foundered with the sub-classing there -- Apple rightfully refuses to implement some of Custom Elements API because it flies in the face of Liskov's Substitution Principle).
Not having the page break because of a small mistake. Though I did get pretty good at writing XHTML, and strictness is a blessing in certain cases.
Fail fast is a feature, not a bug. It's much better to get clear and actionable feedback rather than the page silently rendering incorrectly in some subtle manner.
What do you think of CSTML? It's my attempt to heal the rift between XML and HTML5, as well as solving all the problems that made XML feel onerous to use... https://docs.bablr.org/guides/cstml

It's simple to parse like JSON, it has namespaces like XML (but better), and it doesn't require you to repeat the name of every element twice.

I looked at CSTML, and frankly, it looks like any other improvement that upon first glance may seem like definite improvement, but the trouble with these dialects or ideas is that it's not the format that's hard to incorporate -- even after you prove it is sound (undesirable parsing ambiguities can something show themselves _after_ you wrote a parser to verify the language grammar etc), but pushing for adoption is. XML didn't die only because it was verbose, it died because the people who may have been convinced of some of the featured really disliked by everyone else, refused to budge -- perhaps they thought that repeating the tag's name is a good thing because it forces one to be diligent or whatever * points to some research paper that supposedly proves repeating text improves accuracy *. It's the equivalent of doubling down when opposed. So XML basically became more XML the more criticism piled up, and as it ossified it died. CSTML, as likely much of anything else that aims at replacing SGML/XML/HTML, is like projects -- ideas are cheap, going through with it is hard. Before CSTML is a long path of adoption, and today with HTML 5, it's even more narrow unless Google, for one, suddenly decides it's the best thing since `<parsed-bread>` (closing tag is omissable).

I think some straightforward YAML schema for representing HTML 5, may have more traction because both are existing languages so not much extra tooling would be required. I could for instance write my Web blog in YAML that is unambigously and simply compiled into HTML 5 (without sacrificing a _single feature_ of the latter), so I don't have to actually type HTML (5). Not everyone uses React or JSX or what have you, and Markdown implementations in practice are often lacking for truly rich blog articles. Then again, if you have a blog article with interactice diagrams, sliders and ad-hoc questionnaires, _XML_ (or a YAML representation thereof, for much the same reason as outlined earlier) _is_ IMO a good language _in form_ -- I have used XSLT with good effect to just stick to a domain-specific language for my blog articles, and have a single XSL stylesheet render uniform HTML page linked to a CSS stylesheet that was basically a posterchild for the coveted content-presentation separation in practice.

I've taken care of the parsing ambiguities. There were some, and yeah they took me a while to find. I've been working for a while though : )

Also completely with you on wanting a language I can use to losslessly write HTML, and CSTML does that too. That docs page on CSTML is written in CSTML for example: https://github.com/bablr-lang/bablr-docs/blob/trunk/src/cont...

I also think the path to adoption for CSTML is eased considerably by the fact that most CSTML documents will be produced as parser or WYSIWYG editor output rather than hand-written. And yeah, the whole world of XSLT opens back up again with this tech. I loved the idea behind XSLT. It was a great idea. It created a much richer semantic internet, and then let visual presentation be a concern purely secondary to semantics.

> Well, the brackets thing and the necessity to repeat name of every element twice,

As a document format, it's supposed to be hand-written by humans. If you have paragraphs between the opening tag and closing tag, it makes sense to let the reader know what they're seeing the closing of.

After deciding you do want to repeat the element name, the angle brackets make more sense. Otherwise, you can have a syntax like LaTeX's.