This code example is in XHTML, a pattern that attempts to unify HTML with XML. Both languages are quite similar, but there are some crucial differences, so the need to specify a DOCTYPE
.
The Doctype is a statement associating the current document with a DTD ("Document type Definition"), is responsible for defining which exact syntax is used (XML or SGML, of which HTML is a dialect), which elements are allowed, which attributes, etc. The general syntax of this statement is:
<!DOCTYPE root-element PUBLIC "FPI" ["URI"] [
<!-- internal subset declarations -->
]>
or:
<!DOCTYPE root-element SYSTEM "URI" [
<!-- internal subset declarations -->
]>
In his example, the root element is the html
(the main tag of the document), the type is public (because the HTML specification is open to the public), the first value in quotes is a unique identifier for that DTD, and the second value is the public URI of the document describing it.
In this case, it is a XHTML. If it were HTML 4 strict mode, for example, it would be:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
In the case of HTML5, the syntax allows you to omit the declaration of a DTD, saying only that "the document is HTML5" and nothing else:
<!DOCTYPE html>
Already the xmlns
is nothing more than a namespace XML - as a XHTML document is a type of XML, it can have a namespace determining the meaning of each of the elements in that document. If you wanted to embed another type of document within the XHTML, for example SVG or Mathml, and these documents had elements with the same name as the XHTML elements, it could conflict. The use of namespaces helps in this sense by allowing you to prefix the "foreign" elements with an identifier saying that they are elements of a different type of document, with their own namespace. Example:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>A Math Example</title>
</head>
<body>
<p>The following is MathML markup:</p>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<apply> <log/>
<logbase>
<cn> 3 </cn>
</logbase>
<ci> x </ci>
</apply>
</math>
</body>
</html>
Source
In this example above, all elements within math
are considered elements of Mathml, not XHTML, for validation purposes. In this case no prefixes were required (because the elements did not mix), but in other cases they might be needed:
<!-- initially, the default namespace is "books" -->
<book xmlns='urn:loc.gov:books'
xmlns:isbn='urn:ISBN:0-395-36341-6' xml:lang="en" lang="en">
<title>Cheaper by the Dozen</title>
<isbn:number>1568491379</isbn:number>
In the above section, the element title
belongs to the namespace document standard, while the element number
belongs to another namespace.
About XMLNS -> http://www.maujor.com/w3c/xhtml10_2ed.html#ref-xmlns
– PauloHDSousa
Well, if you have the patience to read (and learn English): http://stackoverflow.com/questions/255470/what-are-the-different-doctypes-in-html-and-what-do-they-mean
– Lucas Henrique