3 ms·
Actually you should never use attributes in XML at all to represent data. Your first example is correct. Everyone is just confused because people who didn't kn
by baz00 3y ago
Actually you should never use attributes in XML at all to represent data. Your first example is correct.
Everyone is just confused because people who didn't know this designed HTML. But also everyone is confused because HTML and XML aren't necessarily related other than some parentage in SGML.
- tannhaeuser 3y agoNope. In markup, attributes are for "metadata", that is, anything not rendered to the reader/user, as opposed to (element) content. The entire purpose of markup is to provide a rich text format via decorating plain text usable from any text editor. Data exchange, or any other application where there is no concept of "rendering to the user", is no primary application for markup. If anything, what's wrong with HTML in this respect is that JavaScript and CSS can be put inline into content when these should always go into attributes and/or external resources linked via src/href attributes. And this flaw shows indeed where HTML deviates from SGML proper: when the style and script elements were introduced, their "content" needed to be put into SGML comment tags <!-- and --> such that browsers wouldn't render JavaScript snd CSS as text content. I mean, who came up with this brain-dead design? But CSS is a lost cause anyway. What does it tell you about its designers that they thought, starting with a markup language having pretty intense syntactic constructs already, to tunnel yet another item=value syntax in regular markup attributes? Like replacing <h2 bgcolor=black> by <h2 style="background-color: black"> and then claiming attributes are for "behavior" or whatever nonsense after the fact. Whoever came up with this clearly wasn't a CompSci person. And the syntactic proliferation in CSS completely became out of hand, for the simple reason that HTML evolution was locked down while W3C was focussed on XML/XHTML for over a decade, while the CSS spec process was lenient.