Monday, May 20, 2024
HomeProgrammingWhat is the "xmlns attribute" used in XHTML?

What is the “xmlns attribute” used in XHTML?

The word “XHTML” always comes up when you look up “xmlns attributes”.
In order to know the “xmlns attribute”, you must first know the relationship between “XHTML”, “HTML”, and “XML”.
This article explains “XHTML” and related “XML” and “xmlns attributes”.

Table of contents

  • What is “XHTML”
  • What is “XML”?
  • Relationship between XML and HTML
  • How to write HTML4 and XHTML
    • How to write HTML4
    • How to write XHTML
  • Differences between HTML4 and XHTML
    • Description of “!DOCTYPE”
    • What is an XML Namespace (xmlns)
    • Meaning of end (/)
  • Relationship with HTML5
  • summary

What is “XHTML”

XHTML is a markup language established as an extension of the familiar “HTML” markup language for displaying web pages .
Originally, HTML was only intended for “display” in web browsers, but as a result of being used in web applications, it was thought that stricter rules were needed for writing methods, so “XHTML” was enacted. “about it.

What is “XML”?

XHTML is designed to be written according to the writing rules of “XML”.
XML is an abbreviation for “Extensible Markup Language”, which literally translates to “extensible markup language” .
It is mainly used for data exchange between applications and system configuration files, and is a technology often used when dealing with web applications.

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

However, loading this XML file in a browser just shows the code.
Since it only defines data, XML itself does not have a function to display it beautifully on the screen.

Relationship between XML and HTML

XML has a structure in which markup is nested, and is written in a structure similar to that of HTML.
However, as I explained earlier, HTML was originally a language intended only for “display”, so it is not strictly compatible with XML, and is not described according to the rules of XML.

That ‘s where “XHTML” came in.
By forcing the strict writing style of XML to HTML, XHTML made it possible to set strict rules for easy handling from programs.

How to write HTML4 and XHTML

So what are the differences between writing HTML and XHTML?
First, let’s check the description example.

How to write HTML4

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Sample Web Page</title>
</head>
<body>
  
  <br>
  
</body>
</html>

How to write XHTML

<!DOCTYPE HTML PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Sample Web Page</title>
</head>
<body>
  
  <br />
  
</body>
</html>

Differences between HTML4 and XHTML

HTML4 and XHTML display exactly the same content, but there are some differences.
Actually, “xmlns attribute” is involved here.

  • The description of “!DOCTYPE” is different
  • “xmlns (XML namespace)” is specified
  • The end (/) is described in the br tag

Description of “!DOCTYPE”

The declaration contents of the “!DOCTYPE” tag differ between HTML and XHTML.
The “!DOCTYPE” tag is for declaring the DTD used to interpret the document.
“DTD (Document Type Definition)” defines information on elements (tags) and attribute names that can be used for each version of HTML, so the declared DTD differs between HTML and XHTML.

What is an XML Namespace (xmlns)

Since XML allows you to decide the element names yourself, there are problems such as defining duplicate element names and difficulty in matching with other XML files.
Therefore , by defining an “XML namespace” , a rule is defined that the same element name has the same meaning within that namespace.
XHTML must be written in an XML-compliant way, so it is necessary to set a namespace, but in HTML, the same tags have the same meaning, so XHTML only defines them formally.
It’s enough to think “If you see xmlns characters in HTML format, it’s XHTML”.

Meaning of end (/)

In XML, there is a rule that an element (tag) must be closed whenever it is started.
However, when this rule is applied, the “line break (br)” used as an “empty element” that does not specify content must also be closed.
Therefore, if the tag has no content, it is written as “br /” in the sense that it ends as it is.

Relationship with HTML5

Earlier, I explained how to write in “HTML4”.
Then, how about the description method of “HTML5”?

<!DOCTYPE html>
<html lang="ja">
<meta charset="UTF-8">
<title>Sample Web Page</title>
</head>
<body>
  
  <br>
  
</body>
</html>

HTML5 is an HTML standard enacted later than HTML4 and XHTML, making it easier to describe.
On the other hand, more than 20 years have passed since the establishment of XHTML, and compatibility between HTML and XML has become less important.
As of 2022, all major browsers will support HTML5, so it can be said that there is no need to write in XHTML unless there is a special reason.

summary

I explained XTHML, HTML, XML, and “xmls attributes”.

  • “xmls attribute” is used in XML and XHTML
  • XHTML is a markup language that has been extended to describe HTML in a strictly XML-compliant manner.
  • Collaboration between XML and HTML has become less important, and as of 2022, XHTML will not be used much.

The “xmls attribute” is still used in XML to deal with multiple namespaces, but its relationship with HTML is limited.
If you see it in an application developed in the past, be sure to check it while being aware of the linkage with XML.

RELATED ARTICLES

Leave a reply

Please enter your comment!
Please enter your name here

Recent Posts

Most Popular

Recent Comments