XHTML is a stricter and cleaner version of HTML
XHTML是更严密代码更整洁的HTML版本 .
- XHTML stands for EXtensible HyperTextMarkup Language
XHTML是具有延伸性的超文本标记语言 - XHTML is aimed to replace HTML
出现XHTML目的就是要替代HTML - XHTML is almost identical to HTML 4.01
XHTML和HTML4.01几乎相同 - XHTML is a stricter and cleaner version of HTML
XHTML是更严密代码更整洁的HTML版本 - XHTML is HTML defined as an XML application
XHTML的定义形同将HTML视为XML(从代码的结构上) - XHTML is a W3C Recommendation
XHTML是W3C的推荐标准
XHTML is a combination of HTML and XML (EXtensible Markup Language).
XHTML是HTML和XML(可扩展标记语言)的组合
XHTML将XML的语法和所有HTML4.01的元素结合起来
二. why xhtml
We have reached a point where many pages on the WWW contain "bad" HTML.
可以注意到网上有许多"糟糕(代码乱糟糟)"的HTML页面
XML was designed to describe data and HTML was designed to display data.
XML被用来描述数据而HTML则被用来显示数据(一个内容一个外表)
XML is a markup language where everything has to be marked up correctly, which results in "well-formed" documents. XML是一种合理使用标记的语言(对标记的规范性十分的严格)
Today's market consists of different browser technologies, some browsers run Internet on computers, and some browsers run Internet on mobile phones and hand helds. The last-mentioned do not have the resources or power to interpret a "bad" markup language.
目前市场上有多种浏览器技术,有运行在普通PC机上的,手机或其他一些移动设备上的等等,要说明的是请别让任何一款浏览器花费更多的资源来解释"糟糕"的标记语言
Therefore - by combining HTML and XML, and their strengths, we got a markup language that is useful now and in the future - XHTML.
因此,通过HTML和XML的结合,发挥它们各自的长处,就获得了现在并且在将来都实用的标记语言-XHTML
等到其它浏览器都升级至支持XML的时候,XHTML能够被所有支持XML的设备读取,现在XHTML给你一个“加工”HTML文档的机会,让这些文档能够在所有的浏览器中查看,并且有良好的向后兼容性。
三.comparison of xhtml and html
The Most Important Differences:
最主要的区别:
- XHTML elements must be properly nested
XHTML元素必须合理嵌套 - XHTML documents must be well-formed
XHTML文档形式上必须符合规范 - Tag names must be in lowercase
标签必须使用小写 - All XHTML elements must be closed
所有的XHTML元素都必须有始有终
Elements Must Be Properly Nested
元素必须合理嵌套In HTML some elements can be improperly nested within each other like this:
在HTML中一些元素可以不使用正确的相互嵌套: <b><i>This text is bold and italic</b></i>
In XHTML all elements must be properly nested within each other like this:
在XHTML中所有元素必须合理的相互嵌套:
Documents Must Be Well-formed
文档形式上必须符合规范
All XHTML elements must be nested within the <html> root element. All other elements can have sub (children) elements. Sub elements must be in pairs and correctly nested within their parent element. The basic document structure is:
所有的XHTML元素必须被嵌在<html> 根元素之中。所有其它的元素可以有自己的子元素。位于父元素之内的子元素必须成对出现且使用正确的嵌套。文档的基本构架为:
<head> ... </head>
<body> ... </body>
</html>
Tag Names Must Be In Lower Case
标签必须使用小写
This is because XHTML documents are XML applications. XML is case-sensitive. Tags like<br>
and <BR>
are interpreted as different tags.
因为XHTML文档是XML应用产物,XML是区分大小写的,所以<br>和<BR>会被认为是两种不同的标签。
This is wrong:
这就是错误的:
<P>This is a paragraph</P>
</BODY>
This is correct:
这才是正确的:
<p>This is a paragraph</p>
</body>
All XHTML Elements Must Be Closed
所有的XHTML元素都必须有始有终
Non-empty elements must have an end tag.
非空元素必须得有结束标签
This is wrong:
这是错误的写法:
<p>This is another paragraph
This is correct:
这是正确的:
<p>This is another paragraph</p>Empty Elements Must Also Be Closed
空标签也得关闭
Empty elements must either have an end tag or the start tag must end with/>
.
空标签同样也得关闭,可以是在开始标签后加上/>
This is wrong:
这是错误的写法:
Here comes a horizontal rule:<hr>
Here's an image <img src="happy.gif" alt="Happy face">
This is correct:
正确的是这样:
Here comes a horizontal rule:<hr /> Here's an image <img src="happy.gif" alt="Happy face" />
四。Some More XHTML Syntax Rules:
更多XHTML语法规则:
- Attribute names must be in lower case
属性名称必须小写 - Attribute values must be quoted
属性值使用双引号 - Attribute minimization is forbidden
不允许简写属性 - The id attribute replaces the name attribute
用id属性来替换name属性,To interoperate with older browsers for a while, you should use both name and id, with identical attribute values, like this:
注: 针对版本比较低的浏览器,应该同时使用name和id属性,并使它们两个的值相同 - The XHTML DTD defines mandatory elements
XHTML DTD 用来定义必要的元素
要让XHTML兼容当前的浏览器应该在/标记前添加空格
Mandatory XHTML Elements
必要的XHTML元素
All XHTML documents must have a DOCTYPE declaration. The html, head and body elements must be present, and the title must be present inside the head element.
所有XHTML文档都必须有 DOCTYPE(文档类型) 声明. 文档内必须含有html,head,body元素,而且title元素必须出现在head元素内.
This is a minimum XHTML document template:
微型 XHTML 文档样本:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Title goes here</title>
</head> <body>
</body> </html>
Note: The DOCTYPE declaration is not a part of the XHTML document itself. It is not an XHTML element, and it should not have a closing tag.
注: DOCTYPE声明并不是XHTML文档自身的一部分。它也不属于XHTML元素,不需要有关闭标签。
Note: The xmlns attribute inside the <html> tag is required in XHTML. However, the validator on w3.org does not complain when this attribute is missing in an XHTML document. This is because "xmlns=http://www.w3.org/1999/xhtml" is a fixed value and will be added to the <html> tag even if you do not include it.
注: XHTML文档要求xmlns属性出现在html标签中。然而,w3.org的校验器不会由于这个属性没有出现在你的XHTML文档中而报告错误。这是因 为"xmlns=http://www.w3.org/1999/xhtml"是一个固定的值,即使你的文档里没有包含它,它也会自动加上的。
五。XHTML DTD
The XHTML standard defines three Document Type Definitions.
XHTML标准制订了三种文档类型定义
The most common is the XHTML Transitional.
使用最普遍的是XHTML过渡型类型
必须得有<!DOCTYPE>
An XHTML document consists of three main parts:
XHTML文档主要由下面三个方面构成
- the DOCTYPE
- the Head
- the Body
文档声明必须出现在XHTML文档的首行。
There are currently 3 XHTML document types:
当前的三类 XHTML 文档类型:
- STRICT
严密型 - TRANSITIONAL
过渡型 - FRAMESET
框架型
XHTML 1.0 严密型 <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Use this when you want really clean markup, free of presentational clutter. Use this together with Cascading Style Sheets.
当你想要从以前那种混乱的观念中解脱出来,并想要真正整洁的代码的话,就使用这个DTD。并将它和样式表一起使用
XHTML 1.0 过渡型 <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Use this when you need to take advantage of HTML's presentational features and when you want to support browsers that don't understand Cascading Style Sheets.
使用这个DTD可以发挥一些HTML的优势或者当你想要支持一些不支持样式表的浏览器时也可以使用这个。
XHTML 1.0 框架型 <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
Use this when you want to use HTML Frames to partition the browser window into two or more frames.
当你想要使用HTML的框架就用这个DTD
An XHTML document is validated against a Document Type Definition.
依靠文档类型定义来校验XHTML文档。
Validate XHTML With A DTD
通过DTD校验XHTML
An XHTML document is validated against a Document Type Definition (DTD). Before an XHTML file can be properly validated, a correct DTD must be added as the first line of the file.
要正确校验XHTML文件就必须在首行加入恰当的DTD。