Why do you declare yourself PUBLIC and xmlns using W3.org site?

Asked

Viewed 207 times

2

I have always had this doubt, because most sites declare arguments PUBLIC on the tag !DOCTYPE and xmlns on the tag html and because always the values of these arguments are links to the W3.org? I searched several times but found nothing, must have missed the search term.

Example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  • 1

    About XMLNS -> http://www.maujor.com/w3c/xhtml10_2ed.html#ref-xmlns

  • 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

2 answers

5


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.

3

I believe you are looking at HTML4 pages. HTML5 pages have already changed their pattern.

The idea of HTML4 was to maintain high compatibility with the XML format. In this format, things can be very restricted, in order to be able to validate against a file that contains the rules of what may or may not exist in XML. An example of this is the Brazilian NF-e. Fields are marked with an XMLNS (XML Name Space) indicating that tipo (or type) should count each 1, example: string, date, or even some kind of markup. These are Xsds files (XML Schema).

HTML4 had this idea, that everything would be exactly too defined and that it could use validators to check if the HTML page had an error.

But the thing evolved. It was realized the importance of using more markings to identify sections (<footer> , <header>, <section>, etc) and also to add non-standard attributes (those that are in us within Divs and others, for example <div data-info="X">) which are added dynamically by jquery, Angularjs, D3 and other libraries in order to make HTML richer without "breaking it". It makes no sense to validate it against a namespace. So the thing has changed.

And one last thing. Since who specified which was the HTML "Pure" is the W3C, they always had the newest and updated Xsds according to the versions of the standards. So you always had to point to them.

I don’t know if this is your curiosity, but I hope it helps your research.

  • 1

    I agree with what you wrote, but note that HTML4 is different from XHTML. These statements in the AP example refer to XHTML and not HTML in any version. In addition, HTML5 did not abandon this validation logic, etc., it simply left implicit certain things if you don’t explicitly declare them. (i.e., you can still validate HTML5 against a namespace)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.