RK* - rikkertkoppes.com

thoughts

[SGML] the NET shorttag

Now we're all validating our documents, please tell me why this document (view source) validates and this document (view source) does not validate (hint: you might want to take a look at the parse tree).

And why are people talking that XHTML served as text/html should show ">" charachters all over the place.

The answer is the SGML NET (null end tag) shorttag. In SGML it is legal to close your tags like <em/bla/ instead of <em>bla</em>. So when you use XHTML things like <br /> in SGML (read: XHTML documents served as text/html), the tag should close when the parser encounters the "/" and the ">" remains. Now the ">" is treated as character data and shown. Most browsers do not do this however, so that's a pre for the unaware.

Now you know what it is with my two documents. The a opening tag in the first document closes as soon as the parser encounters the first "/" in that URL, then reads an empty element contents and closes the tag (second "/"). Everything after it is treated as character data, including that bogus attribute. So everything is correct here.

The second document does not validate because of the same reason: the a is already closed when the parser reaches </a>, so an error occurs.

This can be avoided by adding quotes to attributes, in fact, you are only alowed to omit those quotes if the attribute value only contains letters (a-z and A-Z), digits (0-9), hyphens (ASCII decimal 45), periods (ASCII decimal 46), underscores (ASCII decimal 95), and colons (see W3C: attributes in HTML 4.01 on this).

Note that this is only a validation issue, frequently used browsers do not support the NET shorttag (lynx does). See this example.

Further reading


comment

HopeSeekr of xMule (2005-03-17)

I found this *incredibly* interesting. If I had known about this 5 years ago, I would have used it :-) However, all of my pages are now totally 100% XHTML 1.1 compliant :-)) See http://www.astro-tickets.com/ for a recent example.

Rikkert (2005-03-17)

Sorry to say: they're not (at least your example). XHTML 1.1 should be served as application/xhtml+xml, which makes XHTML 1.1 useless because it will not work in IE

Furthermore, the NET shorttag never worked in browsers that existed 5 years ago (that's the reason you get away with XHTML served as text/html). See Ian Hicksons article for example.

Add comment
older articles

AdministrationAtom feed