These are the answers to last week’s Web Developer Quiz. If you have not attempted the quiz yourself, I recommend you do so before reading the following answers. All the responses to the quiz from ealier this week were made public earlier today.
Validation
There is only one error within the sample document, validate it and see for yourself:
Line 4, column 11: there is no attribute “ALIGN”
The align attribute is not valid in HTML 4.01 Strict because it is deprecated. It is valid in HTML 4.01 Transitional. For information about why line 7 isn’t an error, refer to the validation quiz and associated answers I published earlier.
Elements in the DOM
There are 3 p elements within the document. The syntax: <>
in
an empty start-tag, an unsupported SHORTTAG
feature from SGML. It basically
means to open the most recent unclosed element. Similarly, </>
is
an empty end-tag which ends the most recent open element.
The em
element will not be present because, despite appearances to the contrary,
it is actually commented out. The head
and body
elements will still be present,
even though their start- and end-tags have been omitted.
Validate it and look at the Parse Tree to confirm these answers.
Semantics
The unordered list (option 3) is the most semantically correct. A stylesheet may be used to style it in any way desired.
The <h1>
element without the style
attribute or the class
attribute
with a presentational class name is the most appropriate markup for a document
title. An external stylesheet may be used, and is the recommended way, to horizontally
centre it in a visual medium using a large, bold font. The use of the style
attribute or the presentational class name is not recommended because it fails
to separate the markup from the presentation.
Everyone got these 2 questions correct. Well done. In hindsight, I wish I had made these more difficult, but since semantics is not an exact science, I found that (in general) the more complicated the question, the less specific the answer could be. So, I settled for relatively easy questions for things that beginners tend to markup poorly.
Character References
- For an HTML 4.01 document: the numeric character reference:
’
and the character entity reference:'
are invalid. - For an XHTML 1.0 document: technically, none of them are invalid; however
the numeric character reference:
’
, while it is not prohibited in XML, refers to a Unicode control character and should not be used anyway. - For a generic XML document with no DTD, only the character entity reference:
’
is invalid.'
is valid because it is one of the 5 predefined entities in XML.
Since few people correctly answered these questions, I will be providing more information about this in tomorrow’s post.
Media Types (MIME)
An XHTML 1.1 document SHOULD NOT be served with the text/html
MIME type. See the XHTML
Media Types Note for more information.
An XHTML 1.0 document MAY be served as text/html
when
the document conforms to the Appendix
C HTML Compatibility Guidelines in the
XHTML 1.0 Recommendation. Those who pointed out that this is ludicrous get
a bonus point.
If any of you have any questions or comments regarding this quiz, please feel free to let me know. The feedback I have recieved, or will recieve, regarding this quiz will help me a lot with the next one I’m planning, which will most likely be a CSS quiz of some kind, possibly followed by a JavaScript/DOM quiz if I have time. Beyond that, well, you’ll have to wait and see.
Regarding the character reference ’ being invalid in HTML 4.01—I’m not so sure actually. Sure, the W3C validator says it is, but testing it in nsgmls yields different results and ’ validates perfectly.
The SGML Handbook says the following in Annex B (45:18). (Emphasis mine):
In the SGML declaration for HTML, code points 128-159 are marked UNUSED, which makes them non-SGML characters, so point c) should apply.
I did escape &# 146; up there^. Didn’t seem to work though.
Thanks for publishing the answers; this is indeed very interesting! I’m anticipating the next quiz. 🙂
Actually, since you seem to know a lot about SGML, might you consider doing a post about a few more of those unsupported features sometime? It might help to clear up some validation mysteries for some people.
I have one question though; is it possible that you could elaborate on the correct commenting syntax? I think many people (including myself) would be interested in knowing exactly why the
em
element isn’t in the DOM.Charl, I think Lachlan have covered some of these subjects before, check the archives.
Regarding the comment syntax: In SGML, a comment declaration starts with the abstract delimiter MDO (markup declaration open). It’s up to the application to define it. Most applications however, use the so called reference concrete syntax (RCS), in which MDO is defined as
<!
. Comment declarations ends with MDC (markup declaration close) which is defined as > in the RCS.Comment declarations consists of 0 or more comments, which means that
<!>
(often called empty or null comment declaration) is legal.Comments (not the same as comment declaration) start and ends with the COM (comment start or end) delimiter, which in the RCS is defined as
--
. No whitespace is permitted between MDO and the first comment. It is however permitted before MDC.In the quiz, there was
<!-- -- --> <em>It’s not hard!</em> <!-- -- -->
, i.e., MDO, COM (starts the comment), COM (ends), COM (start), a comment consisting of ” > <em>It’s not hard!</em> <!– “, COM (end), COM (start), COM (end), MDC.I hope you understand better now.
Lachlan, you really need a preview button.
I try again (I forgot the comments consisting of only one space too I see now):
<!-- -- --> <em>It’s not hard!</em> <!-- -- -->
MDO, COM (start), comment (” “), COM (end), COM (start), comment (“> <em>It’s not hard!</em> <!”, COM (end), COM (start), comment (” “), COM (end), MDC)
David: regarding ’, you are correct. It is technically not invalid, though it is a reference to a unicode control character and it’s meaning as a non-SGML character is undefined. The W3C validator only issues a warning for using it HTML, but it should be treated as an error and should not be used. I’ll be explaining this is much more detail in my next post tonight.
Regarding the preview button, I know I need one. I really need to work on this awful default Word Press installation. In the mean time, you could try writing your comments in your favourite HTML editor and then copy and paste when you’re ready.