Following yesterday's post about XHTML validation and the script tag (which I assumed to be a browser problem, not a code problem) I got an email from megnut reader Maurice saying,
Script element should always have an end tag and really can't be considered a singular or "empty" type tag like, say, the Image tag or something. I guess it must be a minor glitch in the validator or something.
Since that didn't sound right to me, I decided to go to the source: XHTML 1.0 The Extensible HyperText Markup Language, Section 4.3: For non-empty elements, end tags are required. It says,
4.3. In SGML-based HTML 4 certain elements were permitted to omit the end tag; with the elements that followed implying closure. XML does not allow end tags to be omitted. All elements other than those declared in the DTD as EMPTY must have an end tag. Elements that are declared in the DTD as EMPTY can have an end tag or can use empty element shorthand
So I examine the DTD and see that
<script> does not contain EMPTY, which would support Maurice's assertions that the code was in fact, not valid, and there was a glitch in the validator. But then I looked at the definition for
<p> and it doesn't contain EMPTY either. But you can use
<p /> instead of
<p></p>. Or at least, I thought you could. Plus it seems weird since a
<script> in reality can be empty, like in my example when it's linked to an external file. So why's the DTD saying it can't be? Anyone actually understand what's going on here?
3 thoughts on “More on XHTML”
A better question would be why the script tag is used to link to external script files in the first place. After all, the link tag is specifically meant to tie external documents (of any and all kinds, not just stylesheets) to a specific page. Personally, I think the src attribute of the script tag should be deprecated, the script tag meant solely for in-page scripts, and the link tag slightly modified to take into account linked script sheets.
But that would require pretty much every browser to change in order to work correctly. Oh well, here’s to hoping.
(Out of curiousity, when would you ever use p /? Semantically speaking, it seems to me that an empty paragraph shouldn’t be a paragraph. Is there a specific instance that makes sense that I’m missing? 🙂
While p/ is legal HTML 4.01, which makes the end tag for element “p” optional, XHTML 1.0 tightened the rules and required end tags for all non-empty elements like “p” as you pointed out. Since “script” is a non-empty element, XHTML requires an end tag for it. Obviously, defining an element as “empty” doesn’t always correspond with its actual use but a specification is a specification.
You can’t have an element both empty and not empty. If script was marked up as being EMPTY, what would happen to embedded scripts? It’s the same with textarea — is illegal, although 99% of the time it’s used . Marking up an element as not EMPTY is the safe way — you can still say , but you can also say …, not the case if it was EMPTY.
By the way, is illegal.
Comments are closed.