In your question title, you ask about HTML, SGML and XML as if they are the same thing, but they are not. In fact, they are very different in precisely that area which you are asking about.
In particular, SGML has both Null End Tags and Implied End Tags (and Implied Elements as well), and since HTML is an application of SGML, it inherits those.
Null End Tags allow you to leave out the name of the End Tag. Instead of
<tag>content</tag>
You can also write
<tag/content/
Implied End Tags allow you to leave out the End Tag altogether, if it is clear from the context that there must be an End Tag. For example, in HTML, a body
element cannot be inside a title
or head
element, therefore you can write
<html>
<head>
<title>The Title
<body>
and both the title
and head
elements will be implicitly closed.
End Tags are also implied at the end of the document: all elements will be closed in reverse order.
With Implied Elements, you can leave out both Start and End Tags: since p
is only allowed within body
, the first p
will imply a body
:
<html>
<head>
<title>The Title
<p>
Here, there is a body
element in the document, even though there are no body
tags.
Putting it all together, you get something like this:
<HTML /
<HEAD /
<TITLE / > /
<P / >
This is a complete, 100% well-formed, 100% valid HTML document. (Well, it's missing the DOCTYPE
declaration, but if you add one, you can run it through the W3C validator as HTML 1.0, 2.0, 3.2 and 4.01, even as Strict.)
It is semantically equivalent to the following XHTML:
<html>
<head>
<title>
>
</title>
</head>
<body>
<p>
>
</p>
</body>
</html>
Now, which one of the two is easier to read?
(Actually, that's a serious question. I'm particularly interested in what seasoned Lisp programmers have to say.)
<tag1> <tag2> </> </>
is nice when you only have 1 line. Think of a file that 10M and you have a missing close tag. How do you identify which one is missing.<tag1 <tag2 >>
, so for example<tag1 some huge amount of text <tag2 another huge amount > third huge amount > fourth huge amount
. You can jump from beginning to the end of such tag, in editors who support it (in Vim, it is just by%
, so it is very easy thing). Parameters, for they must be there and they must not break previous rule, might be then something like<tag #parameters # text and tags enclosed>
...