HTML5 Guidelines for Web Developers

(coco) #1
1.3 In Medias Res 15

We get another error message in answer—this time with the comment that the
document is not yet complete and therefore invalid:



  1. Error: End of file seen when expecting text or an end tag.


If we fix this error by adding the end tag , this error message disappears
as well and we have created the shortest possible HTML5 document:


<!DOCTYPE html>


Error recognition in the validator is based on one of the key features of HTML5,
the HTML parser. Unlike all previous specifications, it was formulated to the last
detail, and with its 90 pages is about as exciting to read as the local phone book.
From a technical point of view, however, this chapter is essential, because it de-
fines how the HTML5 markup should be parsed and how the document’s DOM
tree should be structured.


Our preceding mini example generates in reality a complete HTML5 DOM tree,
including html, head, and body elements. You can prove this with another tool,
the HTML5 Live DOM Viewer, at http://livedom.validator.nu. Give it a go!


1.3.3 And What About XHTML?


The HTML5 specification basically defines an abstract language for describing
documents and web applications with APIs for interaction, which are represent-
able in an in-memory DOM tree. It does not matter which syntax is used as the
basis for creating this DOM tree—HTML is one of them, and XHTML is another.
What matters is always the result after parsing, which is a valid DOM-HTML tree
in both cases.


So the decision whether to use HTML or XHTML when creating documents is
up to the author. HTML is more widely used, easier to write, more forgiving with
small syntax errors, and requires the MIME type text/html for output. XHTML
follows the strict XML rules (keyword well-formedness) and always has to use an
XML MIME type, such as text/xml or application/xhtml+xml, which was not
the case previously with XHTML 1.1.


The Hello world! example in XHTML5 manages without DOCTYPE but does require
a valid XML declaration instead, which can be wrapped up in the encoding, and
of course it has to be well-formed:


<?xml version="1.0" encoding="UTF-8"?>




Hello world! in HTML5
Free download pdf