Why is PUBLIC and xmlns declared using site w3.org?

2

I've always had this doubt, because most sites declare PUBLIC arguments in the !DOCTYPE and xmlns tag in the html tag and because the values of these arguments are always w3.org in>? I searched several times but did not find anything, 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">
    
asked by anonymous 23.12.2015 / 18:27

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 DOCTYPE .

The Doctype is a statement that associates the current document with a Document type definition ), this is responsible for defining the exact syntax used (XML or SGML , of which HTML is a dialect), what elements are allowed, what attributes, etc. The general syntax for this statement is:

<!DOCTYPE root-element PUBLIC "FPI" ["URI"] [ 
<!-- internal subset declarations -->
]>

or:

<!DOCTYPE root-element SYSTEM "URI" [ 
<!-- internal subset declarations -->
]>

In your example, the root element is html (the main document tag), the type is public (because the HTML specification is open to the public), the first value in quotation marks is a unique identifier for that DTD , and the second value is the public URI of the document that describes it.

In this case, this is an XHTML. If it were HTML 4 strict mode, for example, 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>

Since xmlns is nothing more than a namespace XML - as a document XHTML is a type of XML, it can have a namespace that determines the meaning of each element in that document. If you wanted to embed another type of document within XHTML, such as SVG or MathML, and those documents had elements with the same name as the XHTML elements, it could conflict. The use of namespaces helps in this, 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>

Font

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 (since 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 title element belongs to the default of the document, whereas the number element belongs to another namespace .

    
24.12.2015 / 00:06
3

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

The idea of HTML4 was to maintain high compatibility with XML format. In this format, things can be tight, so you can validate against a file that contains the rules of what may or may not exist in XML. An example of this is Brazilian NF-e. Fields are marked with an XMLNS (XML Name Space) that indicates that tipo (or type ) must count every 1, example: string, date, or even some type of markup. These are XML Schema (XSD) files.

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

But the thing has evolved. The importance of using more tags to identify sections ( <footer> , <header> , <section> , etc) and also to add non-default attributes (those inside us within divs and others such as <div data-info="X"> ) that are dynamically added by jquery, angularjs, d3 and other libraries to make HTML richer without "breaking it". It does not make sense to validate this against a namespace. Then the thing changed.

And one last thing. As anyone who specified "Pure" HTML is W3C, they always had the newest and updated XSDs according to the standards versions. So you always had to point them out.

I do not know if this is your curiosity, but I hope it helps in your searches.

    
23.12.2015 / 18:38