[XHTML Tutorial]XHTML指南-走向XHTML标准

原文地址:http://www.w3schools.com/xhtml/
翻译:范维肖

XHTML Tutorial
XHTML指南


In this tutorial you will learn the difference between HTML and XHTML. You will also learn how this Web site was converted to XHTML.
在这篇指南中,你可以了解到HTML和XHTML的不同。你也能学习这个网站是怎样转换到XHTML标准的。

Introduction To XHTML
XHTML入门

XHTML is a new, stricter and cleaner version of HTML.
XHTML是新的、严格的并且是干净的HTML的一个版本。

What Is XHTML?
什么是XHTML?
XHTML stands for EXtensible HyperText Markup Language
XHTML is aimed to replace HTML
XHTML is almost identical to HTML 4.01
XHTML is a stricter and cleaner version of HTML
XHTML is HTML defined as an XML application
XHTML 是EXtensible HyperText Markup Language(可扩展的超文本标记语言)的缩写
它的目标是要代替HTML
它与HTML 4.01相比是几乎完全相同的
它是HTML的一个严格、干净的版本
它是将HTML定义为XML应用程序


What You Should Already Know
Before you continue you should have a basic understanding of the following:
1.HTML and the basics of building Web pages
2.The basics of XML

你应该已经掌握的:
在我们继续学习之前你应该对下面的知识有个基本的了解:
1.HTML语言和制作网页基本的一些基础的东东
2.XML的基础知识

XHTML is the official HTML standard

XHTML 1.0 became an official W3C Recommendation January 26, 2000.

XHTML是官方HTML的标准
XHTML 1.0 在2000年1月26日成为W3C官方推荐的标准。

A W3C Recommendation means that the specification is stable, that it has been reviewed by the W3C membership, and that the specification is now a Web standard.
W3C的推荐意在规范的稳定,它已经被W3C小组反复修改使之现在的规范成为了我们网络的标准

XHTML是官方HTML的标准
XHTML 1.0 在2000年1月26日成为W3C官方推荐的标准。

A W3C Recommendation means that the specification is stable, that it has been reviewed by the W3C membership, and that the specification is now a Web standard.
W3C的推荐意在规范的稳定,它已经被W3C小组反复修改使之现在的规范成为了我们网络的标准

W3C defines XHTML as the latest version of HTML. XHTML will gradually replace HTML.
W3C将XHTML定义为HTML的最新版本,并且它会逐渐的取代HTML

All New Browsers Support XHTML
XHTML is compatible with HTML 4.01.
All new browsers have support for XHTML.
所有新的浏览器都支持XHTML
XHTML与HTML4.01是一致的,所以所有新的浏览器都支持它。

所有新的浏览器都支持XHTML
XHTML与HTML4.01是一致的,所以所有新的浏览器都支持它。

所有新的浏览器都支持XHTML
XHTML与HTML4.01是一致的,所以所有新的浏览器都支持它。

What You Should Already Know
Before you continue you should have a basic understanding of the following:
1.HTML and the basics of building Web pages
2.The basics of XML

你应该已经掌握的:
在我们继续学习之前你应该对下面的知识有个基本的了解:
1.HTML语言和制作网页基本的一些基础的东东
2.XML的基础知识

XHTML is the official HTML standard

XHTML 1.0 became an official W3C Recommendation January 26, 2000.

XHTML是官方HTML的标准
XHTML 1.0 在2000年1月26日成为W3C官方推荐的标准。

A W3C Recommendation means that the specification is stable, that it has been reviewed by the W3C membership, and that the specification is now a Web standard.
W3C的推荐意在规范的稳定,它已经被W3C小组反复修改使之现在的规范成为了我们网络的标准

XHTML是官方HTML的标准
XHTML 1.0 在2000年1月26日成为W3C官方推荐的标准。

A W3C Recommendation means that the specification is stable, that it has been reviewed by the W3C membership, and that the specification is now a Web standard.
W3C的推荐意在规范的稳定,它已经被W3C小组反复修改使之现在的规范成为了我们网络的标准

W3C defines XHTML as the latest version of HTML. XHTML will gradually replace HTML.
W3C将XHTML定义为HTML的最新版本,并且它会逐渐的取代HTML

All New Browsers Support XHTML
XHTML is compatible with HTML 4.01.
All new browsers have support for XHTML.
所有新的浏览器都支持XHTML
XHTML与HTML4.01是一致的,所以所有新的浏览器都支持它。

所有新的浏览器都支持XHTML
XHTML与HTML4.01是一致的,所以所有新的浏览器都支持它。

所有新的浏览器都支持XHTML
XHTML与HTML4.01是一致的,所以所有新的浏览器都支持它。

XHTML is a combination of HTML and XML (eXtensible Markup Language).
XHTML是HTML和XML的有机结合。
XHTML consists of all the elements in HTML 4.01 combined with the syntax of XML.
HTML4.01中的所有元素与XML的语法相结合组成了XHTML。
Why XHTML?
我们为什么用XHTML呢?
We have reached a point where many pages on the WWW contain "bad" HTML.
互联网发展到现在,已经出现了太多的糟糕的HTML页面。
The following HTML code will work fine if you view it in a browser, even if it does not follow the HTML rules:
下面的这些HTML代码在你的浏览器中能够很好的显示,即使它并不是遵循HTML标准的。

<html>
<head>
<title>This is bad HTML</title>
<body>
<h1>Bad HTML
</body>


XML is a markup language where everything has to be marked up correctly, which results in "well-formed" documents.
XML是一种标记语言,每一处都必须被正确的标记,它的结果必然是一个“格式良好”的文档。
XML was designed to describe data and HTML was designed to display data.
XML是被设计用来描述数据的,而HTML是被设计用来显示数据的
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.
现在的市场上有很多种浏览器技术,有一些可以在电脑上运行,也有一些可以在移动电话或掌上电脑上运行。最后要说明的是它们都没有足够的资源或能去解释一种“糟糕的”标记语言。
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
XHTML pages can be read by all XML enabled devices AND while waiting for the rest of the world to upgrade to XML supported browsers, XHTML gives you the opportunity to write "well-formed" documents now, that work in all browsers and that are backward browser compatible !!!
等到世界上的其它浏览器已升级为支持XML的时候,XHTML能够被所有支持XML的设备读取,XHTML给你一个写出“格式良好的”文档的机会,这些文档能够在左右的浏览器中查看,并且有良好的向后兼容性。

You can prepare yourself for XHTML by starting to write strict HTML.
你可以通过开始书写严格的HTML代码来为你的XHML之路做准备

How To Get Ready For XHTML
如何开始XHTML呢?
XHTML is the next generation of HTML, but it will of course take some time before browsers and other software products are ready for it.
XHTML是HTML的下一代语言,当然,在新的浏览器和其他的相关软件产品出现之前,它将延迟一段时间才能普及。
In the meantime there are some important things you can do to prepare yourself for it. As you will learn from this tutorial, XHTML is not very different from HTML 4.01, so bringing your code up to 4.01 standards is a very good start. Our complete HTML 4.01 reference can help you with that.
其间,有一些重要的事情你能够去做来为它的学习做准备。就像你可以从这篇指南学到的东西一样,XHTML不是与HTML4.01有很多不同的,所以把你的代码改写程4.01标准是一种非常好的开始,我们完整的HTML4.01参考可以帮助你解决这个问题。
In addition, you should start NOW to write your HTML code in lowercase letters, and NEVER make the bad habit of skipping end tags like the </p>.
另外,现在你应该开始用小写字母来书写你的HTML代码了,并且永远不要再像以前那样有跳过像</p>这样的结尾标记的坏习惯了。
Happy coding!
陶醉于编码之中吧!

The Most Important Differences:
两者最主要的不同:
XHTML elements must be properly nested
XHTML documents must be well-formed
Tag names must be in lowercase
All XHTML elements must be closed
XHTML元素必须正确的嵌套
XHTML文档必须有良好的格式
标记的名字必须用小写字母
左右的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中所有的标记必须被正确的嵌套,像这样:
<b><i>This text is bold and italic</i></b>

Note: A common mistake in nested lists, is to forget that the inside list must be within an li element, like this:
注意:在列表嵌套的时候大家经常会犯一个错误,那就是忘记了插入的新的列表必须在一个<li>标记中,像这样
<ul>
  <li>Coffee</li>
  <li>Tea
    <ul>
      <li>Black tea</li>
      <li>Green tea</li>
    </ul>
  <li>Milk</li>
</ul>

This is correct:
正确的写法
<ul>
  <li>Coffee</li>
  <li>Tea
    <ul>
      <li>Black tea</li>
      <li>Green tea</li>
    </ul>
  </li>
  <li>Milk</li>
</ul>


Notice that we have inserted a </li> tag after the </ul> tag in the "correct" code example.
在这段正确的代码示例中,注意到我们在</ul>之后加了一个</li>标记吗?

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>根标记之中。所有其他的标记能有自己的子标记。位于父标记之内的子标记也必须成对的而且正确的嵌套使用。一个网页的基本结构是这样:

<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:
错误的:
<BODY>
<P>This is a paragraph</P>
</BODY>

This is correct:
正确的

<body>
<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 a paragraph
<p>This is another paragraph

This is correct:
这才是正确的

<p>This is a paragraph</p>
<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:
错误的代码

This is a break<br>
Here comes a horizontal rule:<hr>
Here's an image <img src="happy.gif" alt="Happy face">

This is correct:
正确的:

This is a break<br />
Here comes a horizontal rule:<hr />
Here's an image <img src="happy.gif" alt="Happy face
" />

IMPORTANT Compatibility Note:
关于兼容性的重要的注释:
To make your XHTML compatible with today's browsers, you should add an extra space before the "/" symbol like this: <br  />, and this: <hr  />.
为了使你的XHTML能够兼容现在的浏览器,你必须在/符号之前加一个特殊的空格,就像这样:<br  /><hr  />

Writing XHTML demands a clean HTML syntax.
我们需要用干净的HTML语法来书写XHTML页面
Some More XHTML Syntax Rules:
更多的XHTML语法规定:

Attribute Names Must Be In Lower Case
属性名称必须使用小写

This is wrong:
错误代码:
<table WIDTH="100%">
This is correct:
正确代码:
<table width="100%">

Attribute Values Must Be Quoted
属性值必须加引号

This is wrong:
错误代码:
<table width=100%>
This is correct:
正确代码:
<table width="100%">

Attribute Minimization Is Forbidden
属性的简写方法是被禁止的
This is wrong:

<dl compact>
<input checked>
<input readonly>
<input disabled>
<option selected>
<frame noresize>

This is correct:

<dl compact="compact">
<input checked="checked" />
<input readonly="readonly" />
<input disabled="disabled" />
<option selected="selected" />
<frame noresize="noresize" />

Here is a list of the minimized attributes in HTML and how they should be written in XHTML:
在HTML中简写的属性和其在XHTML中应该怎样书写的列表:
HTML XHTML 
compact compact="compact" 
checked checked="checked" 
declare declare="declare" 
readonly readonly="readonly" 
disabled disabled="disabled" 
selected selected="selected" 
defer defer="defer" 
ismap ismap="ismap" 
nohref nohref="nohref" 
noshade noshade="noshade" 
nowrap nowrap="nowrap" 
multiple multiple="multiple" 
noresize noresize="noresize" 

The id Attribute Replaces The name Attribute
使用id属性来替代name属性
HTML 4.01 defines a name attribute for the elements a, applet, frame, iframe, img, and map. In XHTML the name attribute is deprecated. Use id instead.
对于a, applet, frame, iframe, img和map,HTML 4.01中定义了一个name属性,在XHTML中是不赞成这样做的,使用id来代替name。
This is wrong:

<img src="picture.gif" name="picture1" />

This is correct:

<img src="picture.gif" id="picture1" />

Note: To interoperate with older browsers for a while, you should use both name and id, with identical attribute values, like this:
注意:为了版本比较低的浏览器的存在,你应该同时使用name和id属性,并且它们两个的值应该是相同的,就像这样:
<img src="picture.gif" id="picture1" name="picture1" />

The Lang Attribute
lang属性
The lang attribute applies to almost every XHTML element. It specifies the language of the content within an element.
lang属性可以应用于几乎所有的XHTML元素。它指定了元素中内容的语言集。
If you use the lang attribute in an element, you must add the xml:lang attribute, like this:
如果你像在一个元素中应用lang属性,你必须加上xml:lang属性,像这样:
<div lang="no" xml:lang="no">Heia Norge!</div>
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文档模板
<!DOCTYPE Doctype goes here>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Title goes here</title>
</head><body>
Body text goes here
</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"是一个固定的值,即使你的文档里没有包含它,它也会自动加上的。
You will learn more about the XHTML document type definition in the next chapter.
在下一章的学习中你将学到更多的XHTL文件类型定义的知识。

The XHTML standard defines three Document Type Definitions.
The most common is the XHTML Transitional.
XHTML标准定义了三种文档类型定义,而其中最普通的是XHTML过渡型类型定义

The <!DOCTYPE> Is Mandatory
<!DOCTYPE>标记是强制性的
An XHTML document consists of three main parts:
一个XHTML文档是由下面三个主要部分构成的
the DOCTYPE
the Head
the Body

The basic document structure is:
基本的文档结构是:
<!DOCTYPE ...>
<html>
<head>
<title>... </title>
</head>
<body> ... </body>
</html>

The DOCTYPE declaration should always be the first line in an XHTML document.
DOCTYPE的声明应该总是出现在一个XHTML文档的第一行

An XHTML Example
一个XHTML的例子
This is a simple (minimal) XHTML document:
这是一个简单的XHTML文档的例子
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>simple document</title>
</head>
<body>
<p>a simple paragraph</p>
</body>
</html>

The DOCTYPE declaration defines the document type:
DOCTYPE的声明定义了文档类型
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

The rest of the document looks like HTML:
文档剩下的部分看起来比较像HTML了
<html>
<head>
<title>simple document</title>
</head>
<body>
<p>a simple paragraph</p>
</body>
</html>

The 3 Document Type Definitions
3种文档类型定义
1.DTD specifies the syntax of a web page in SGML.
2.DTD is used by SGML applications, such as HTML, to specify rules that apply to the markup of documents of a particular type, including a set of element and entity declarations.
3.XHTML is specified in an SGML document type definition or 'DTD'.
4.An XHTML DTD describes in precise, computer-readable language the allowed syntax and grammar of XHTML markup.
1.DTD指明了在SGML(通用标记语言标准)下的网页的语法
2.DTD被SGML应用程序所使用,像HTML,为了指明一种特定类型文档的标记的规则,它包括一个对元素和整个实体声明的设定。
3.XHTML被指定在一个SGML文档类型或DTD中
4.XHTML DTD的精确描述,使得计算机能够识别的语言允许语法和XHTML标记的文法可以使用。
There are currently 3 XHTML document types:
三种XHTML文档类型:
STRICT
TRANSITIONAL
FRAMESET
严格型
过渡型
框架型

XHTML 1.0 specifies three XML document types that correspond to three DTDs: Strict, Transitional, and Frameset.
XHTML 1.0指明了三种XML文档类型来适应三种DTD:严格型,过渡型和框架型

XHTML 1.0 Strict
严格型
<!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.
当你想要整洁干净的标记,避免表现层的混乱,把它和CSS一起使用

XHTML 1.0 Transitional
过渡型
<!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.
当你需要充分利用HTML的表现层的特性或者当你想支持那些不支持CSS的浏览器的时候你可以使用过渡型。

XHTML 1.0 Frameset
<!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框架把一个浏览器窗口分割成两个或多个时候使用框架型结构

(转载请注明出处)

The <!DOCTYPE> Is Mandatory
<!DOCTYPE>标记是强制性的
An XHTML document consists of three main parts:
一个XHTML文档是由下面三个主要部分构成的
the DOCTYPE
the Head
the Body

The basic document structure is:
基本的文档结构是:
<!DOCTYPE ...>
<html>
<head>
<title>... </title>
</head>
<body> ... </body>
</html>

The DOCTYPE declaration should always be the first line in an XHTML document.
DOCTYPE的声明应该总是出现在一个XHTML文档的第一行

An XHTML Example
一个XHTML的例子
This is a simple (minimal) XHTML document:
这是一个简单的XHTML文档的例子
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>simple document</title>
</head>
<body>
<p>a simple paragraph</p>
</body>
</html>

The DOCTYPE declaration defines the document type:
DOCTYPE的声明定义了文档类型
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

The rest of the document looks like HTML:
文档剩下的部分看起来比较像HTML了
<html>
<head>
<title>simple document</title>
</head>
<body>
<p>a simple paragraph</p>
</body>
</html>

The 3 Document Type Definitions
3种文档类型定义
1.DTD specifies the syntax of a web page in SGML.
2.DTD is used by SGML applications, such as HTML, to specify rules that apply to the markup of documents of a particular type, including a set of element and entity declarations.
3.XHTML is specified in an SGML document type definition or 'DTD'.
4.An XHTML DTD describes in precise, computer-readable language the allowed syntax and grammar of XHTML markup.
1.DTD指明了在SGML(通用标记语言标准)下的网页的语法
2.DTD被SGML应用程序所使用,像HTML,为了指明一种特定类型文档的标记的规则,它包括一个对元素和整个实体声明的设定。
3.XHTML被指定在一个SGML文档类型或DTD中
4.XHTML DTD的精确描述,使得计算机能够识别的语言允许语法和XHTML标记的文法可以使用。
There are currently 3 XHTML document types:
三种XHTML文档类型:
STRICT
TRANSITIONAL
FRAMESET
严格型
过渡型
框架型

XHTML 1.0 specifies three XML document types that correspond to three DTDs: Strict, Transitional, and Frameset.
XHTML 1.0指明了三种XML文档类型来适应三种DTD:严格型,过渡型和框架型

XHTML 1.0 Strict
严格型
<!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.
当你想要整洁干净的标记,避免表现层的混乱,把它和CSS一起使用

XHTML 1.0 Transitional
过渡型
<!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.
当你需要充分利用HTML的表现层的特性或者当你想支持那些不支持CSS的浏览器的时候你可以使用过渡型。

XHTML 1.0 Frameset
<!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框架把一个浏览器窗口分割成两个或多个时候使用框架型结构

(转载请注明出处)

The <!DOCTYPE> Is Mandatory
<!DOCTYPE>标记是强制性的
An XHTML document consists of three main parts:
一个XHTML文档是由下面三个主要部分构成的
the DOCTYPE
the Head
the Body

The basic document structure is:
基本的文档结构是:
<!DOCTYPE ...>
<html>
<head>
<title>... </title>
</head>
<body> ... </body>
</html>

The DOCTYPE declaration should always be the first line in an XHTML document.
DOCTYPE的声明应该总是出现在一个XHTML文档的第一行

An XHTML Example
一个XHTML的例子
This is a simple (minimal) XHTML document:
这是一个简单的XHTML文档的例子
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>simple document</title>
</head>
<body>
<p>a simple paragraph</p>
</body>
</html>

The DOCTYPE declaration defines the document type:
DOCTYPE的声明定义了文档类型
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

The rest of the document looks like HTML:
文档剩下的部分看起来比较像HTML了
<html>
<head>
<title>simple document</title>
</head>
<body>
<p>a simple paragraph</p>
</body>
</html>

The 3 Document Type Definitions
3种文档类型定义
1.DTD specifies the syntax of a web page in SGML.
2.DTD is used by SGML applications, such as HTML, to specify rules that apply to the markup of documents of a particular type, including a set of element and entity declarations.
3.XHTML is specified in an SGML document type definition or 'DTD'.
4.An XHTML DTD describes in precise, computer-readable language the allowed syntax and grammar of XHTML markup.
1.DTD指明了在SGML(通用标记语言标准)下的网页的语法
2.DTD被SGML应用程序所使用,像HTML,为了指明一种特定类型文档的标记的规则,它包括一个对元素和整个实体声明的设定。
3.XHTML被指定在一个SGML文档类型或DTD中
4.XHTML DTD的精确描述,使得计算机能够识别的语言允许语法和XHTML标记的文法可以使用。
There are currently 3 XHTML document types:
三种XHTML文档类型:
STRICT
TRANSITIONAL
FRAMESET
严格型
过渡型
框架型

XHTML 1.0 specifies three XML document types that correspond to three DTDs: Strict, Transitional, and Frameset.
XHTML 1.0指明了三种XML文档类型来适应三种DTD:严格型,过渡型和框架型

XHTML 1.0 Strict
严格型
<!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.
当你想要整洁干净的标记,避免表现层的混乱,把它和CSS一起使用

XHTML 1.0 Transitional
过渡型
<!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.
当你需要充分利用HTML的表现层的特性或者当你想支持那些不支持CSS的浏览器的时候你可以使用过渡型。

XHTML 1.0 Frameset
<!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框架把一个浏览器窗口分割成两个或多个时候使用框架型结构

XHTML HowTo
如何将我现有的网站转换成XHTML的呢? 
To convert a Web site from HTML to XHTML, you should be familiar with the XHTML syntax rules of the previous chapters. The following steps were executed (in the order listed below):
将一个HTML网站转换到XHTML,你应该熟悉前几章介绍的XHTML的语法规则。下面的内容将帮助您。

A DOCTYPE Definition Was Added
The following DOCTYPE declaration was added as the first line of every page:
将下面的这行代码加到每一页的第一行。

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

Note that we used the transitional DTD. We could have chosen the strict DTD, but found it a little too "strict", and a little too hard to conform to.
注意哦,这里我们使用的是transtitional DTD。当然我们也可以选择Strict DTD的,但是我们发现它有点太严格了,要想完全的去遵循它太难了。

A Note About The DOCTYPE
Your pages must have a DOCTYPE declaration if you want them to validate as correct XHTML.
如果你想使你的页面满足正确的XHTML的有效性你就必须使用DOCTYPE声明。
Be aware however, that newer browsers (like Internet Explorer 6) might treat your document differently depending on the <!DOCTYPE> declaration. If the browser reads a document with a DOCTYPE, it might treat the document as "correct". Malformed XHTML might fall over and display differently than without a DOCTYPE.
然而你必须注意到,比较新的浏览器(像IE6)看到你的页面里的DOCTYPE声明后可能会有不同的对待。如果浏览器读到一个含有DOCTYPE声明的页面,它或许会把这个页面认为“正确的”。如果不使用DOCTYPE的畸形XHTML页面可能会使上面的元素”掉下来“并显示初一个不一样的页面。
Lower Case Tag And Attribute Names
Since XHTML is case sensitive, and since XHTML only accepts lower case HTML tags and attribute names, a general search and replace function was executed to replace all upper case tags with lowercase tags. The same was done for attribute names. We have always tried to use lower case names in our Web, so the replace function did not produce many real substitutions.
XHTML是大小写敏感的,并且只接受小写标记和属性名,你可以使用替换功能来处理。
All Attributes Were Quoted
Since the W3C XHTML 1.0 Recommendation states that all attribute values must be quoted, every page in the web was checked to see that attributes values were properly quoted. This was a time-consuming job, and we will surely never again forget to put quotes around our attribute values.
属性要用括号引起来,这个没有什么简便方法了,却是是项耗时间的工作,只要记得以后别忘了括号就行了。

Empty Tags: <hr> , <br> and <img>
Empty tags are not allowed in XHTML. The <hr> and <br> tags should be replaced with <hr /> and <br />.

This produced a problem with Netscape that misinterpreted the <br/> tags. We don't know why, but changing it to <br /> worked fine. After that discovery, a general search and replace function was executed to swap the tags.

A few other tags (like the <img> tag) were suffering from the same problem as above. We decided not to close the <img> tags with </img>, but with  /> at the end of the tag. This was done manually.
太罗嗦了。就是说有关标记嘛The Web Site Was Validated
After that, all pages were validated against the official W3C DTD with this link: XHTML Validator. A few more errors were found and edited manually. The most common error was missing </li> tags in lists.
你的网站可以通过官方的XHTML有效性检查器来被验证,更多的错误会被检查出并且手工边界,而最通常的错误就是在list里忘记了写</li>了。
Should we have used a converting tool? Well, we could have used TIDY.
可以使用TIDY这个转换工具
Dave Raggett's HTML TIDY is a free utility for cleaning up HTML code. It also works great on the hard-to-read markup generated by specialized HTML editors and conversion tools, and it can help you identify where you need to pay further attention on making your pages more accessible to people with disabilities.
Dave Raggett 的HTML TIDY是一个用来优化HTML代码免费软件,它也能很好的处理那些由特殊的HTML编辑器和转换工具产生的难以理解的标记,同时,它能帮助你标识那些你必须从长远的角度来注意的你的页面能否被残疾人士所使用呢?
The reason why we didn't use Tidy? We knew about XHTML when we started writing this web site. We knew that we had to use lowercase tag names and that we had to quote our attributes. So when the time came (to do the conversion), we simply had to test our pages against the W3C XHTML validator and correct the few mistakes. AND - we have learned a lot about writing "tidy" HTML code.
我们不使用TIDY的原因是当我们做这个网站的时候我们就知道XHTML了,小写和引号我们也知道了。所以当需要转换的时候我们只是简单的通过W3C的XHTML验证器来改正我们的少数的错误。并且,我们已经懂得了要书写干净的HTML代码的。

A DOCTYPE Definition Was Added
The following DOCTYPE declaration was added as the first line of every page:
将下面的这行代码加到每一页的第一行。

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

Note that we used the transitional DTD. We could have chosen the strict DTD, but found it a little too "strict", and a little too hard to conform to.
注意哦,这里我们使用的是transtitional DTD。当然我们也可以选择Strict DTD的,但是我们发现它有点太严格了,要想完全的去遵循它太难了。

A Note About The DOCTYPE
Your pages must have a DOCTYPE declaration if you want them to validate as correct XHTML.
如果你想使你的页面满足正确的XHTML的有效性你就必须使用DOCTYPE声明。
Be aware however, that newer browsers (like Internet Explorer 6) might treat your document differently depending on the <!DOCTYPE> declaration. If the browser reads a document with a DOCTYPE, it might treat the document as "correct". Malformed XHTML might fall over and display differently than without a DOCTYPE.
然而你必须注意到,比较新的浏览器(像IE6)看到你的页面里的DOCTYPE声明后可能会有不同的对待。如果浏览器读到一个含有DOCTYPE声明的页面,它或许会把这个页面认为“正确的”。如果不使用DOCTYPE的畸形XHTML页面可能会使上面的元素”掉下来“并显示初一个不一样的页面。
Lower Case Tag And Attribute Names
Since XHTML is case sensitive, and since XHTML only accepts lower case HTML tags and attribute names, a general search and replace function was executed to replace all upper case tags with lowercase tags. The same was done for attribute names. We have always tried to use lower case names in our Web, so the replace function did not produce many real substitutions.
XHTML是大小写敏感的,并且只接受小写标记和属性名,你可以使用替换功能来处理。
All Attributes Were Quoted
Since the W3C XHTML 1.0 Recommendation states that all attribute values must be quoted, every page in the web was checked to see that attributes values were properly quoted. This was a time-consuming job, and we will surely never again forget to put quotes around our attribute values.
属性要用括号引起来,这个没有什么简便方法了,却是是项耗时间的工作,只要记得以后别忘了括号就行了。

Empty Tags: <hr> , <br> and <img>
Empty tags are not allowed in XHTML. The <hr> and <br> tags should be replaced with <hr /> and <br />.

This produced a problem with Netscape that misinterpreted the <br/> tags. We don't know why, but changing it to <br /> worked fine. After that discovery, a general search and replace function was executed to swap the tags.

A few other tags (like the <img> tag) were suffering from the same problem as above. We decided not to close the <img> tags with </img>, but with  /> at the end of the tag. This was done manually.
太罗嗦了。就是说有关标记嘛The Web Site Was Validated
After that, all pages were validated against the official W3C DTD with this link: XHTML Validator. A few more errors were found and edited manually. The most common error was missing </li> tags in lists.
你的网站可以通过官方的XHTML有效性检查器来被验证,更多的错误会被检查出并且手工边界,而最通常的错误就是在list里忘记了写</li>了。
Should we have used a converting tool? Well, we could have used TIDY.
可以使用TIDY这个转换工具
Dave Raggett's HTML TIDY is a free utility for cleaning up HTML code. It also works great on the hard-to-read markup generated by specialized HTML editors and conversion tools, and it can help you identify where you need to pay further attention on making your pages more accessible to people with disabilities.
Dave Raggett 的HTML TIDY是一个用来优化HTML代码免费软件,它也能很好的处理那些由特殊的HTML编辑器和转换工具产生的难以理解的标记,同时,它能帮助你标识那些你必须从长远的角度来注意的你的页面能否被残疾人士所使用呢?
The reason why we didn't use Tidy? We knew about XHTML when we started writing this web site. We knew that we had to use lowercase tag names and that we had to quote our attributes. So when the time came (to do the conversion), we simply had to test our pages against the W3C XHTML validator and correct the few mistakes. AND - we have learned a lot about writing "tidy" HTML code.
我们不使用TIDY的原因是当我们做这个网站的时候我们就知道XHTML了,小写和引号我们也知道了。所以当需要转换的时候我们只是简单的通过W3C的XHTML验证器来改正我们的少数的错误。并且,我们已经懂得了要书写干净的HTML代码的。


Why XHTML Modularization?
为什么要模块化设计XHTML呢?
XHTML is a simple but large language, containing most of the functionality a web developer will need.
XHTML虽然简单,但是它的内容很多,包括了一个网络设计师需要的绝大多数功能。
For some purposes XHTML is too large and complex, and for other purposes it is much too simple.
XHTML一方面内容繁多复杂,但是从另一个角度来看它却是非常简单的
By splitting XHTML into modules, the W3C (World Wide web Consortium) has created small and well-defined sets of XHTML elements that can be used separately for simple devices as well as combined with other XML standards into larger and more complex applications.
为了将XHTML分割成小的模块,W3C已经建立起了小型大已经定义好了的一系列XHTML元素,他们独立的能被与其他XML标准合并成的大型的更复杂的程序的简单设备所使用。
With modular XHTML, product and application designers can:
通过XHTML模型,程序设计师能够做下面的事情:
1.Choose the elements to be supported by a device using standard XHTML building blocks.
2.Add extensions to XHTML, using XML, without breaking the XHTML standard.
3.Simplify XHTML for devices like hand held computers, mobile phones, TV, and home appliances.
4.Extend XHTML for complex applications by adding new XML functionality (like MathML, SVG, Voice and Multimedia).
5.Define XHTML profiles like XHTML Basic (a subset of XHTML for mobile devices).
1。选择那些能够被使用XHTML构建块标准的设备所支持的元素。
2。在遵循XHTML标准的同时使用XML可以对XHTML扩展。
3。简单化的XHTML可以应用于像掌上电脑、移动电话、电视和家用电器的设备。
4。通过加入心的XML功能(像声音、多媒体的)将XHTML延续到复杂程序的设计上。
5。像XHTML基本(XHTML对于移动设备的一个子集)那样来定义XHTML的轮廓。

XHTML Modules

Module nameDescription
Applet ModuleDefines the deprecated* applet element.
Base ModuleDefines the base element.
Basic Forms ModuleDefines the basic forms elements.
Basic Tables ModuleDefines the basic table elements.
Bi-directional Text ModuleDefines the bdo element.
Client Image Map ModuleDefines browser side image map elements.
Edit ModuleDefines the editing elements del and ins.
Forms ModuleDefines all elements used in forms.
Frames ModuleDefines the frameset elements.
Hypertext ModuleDefines the a element.
Iframe ModuleDefines the iframe element.
Image ModuleDefines the img element.
Intrinsic Events ModuleDefines event attributes like onblur and onchange.
Legacy ModuleDefines deprecated* elements and attributes.
Link ModuleDefines the link element.
List ModuleDefines the list elements ol, li, ul, dd, dt, and dl.
Metainformation ModuleDefines the meta element.
Name Identification ModuleDefines the deprecated* name attribute.
Object ModuleDefines the object and param elements.
Presentation ModuleDefines presentation elements like b and i.
Scripting ModuleDefines the script and noscript elements.
Server Image Map ModuleDefines server side image map elements.
Structure ModuleDefines the elements html, head, title and body.
Style Attribute ModuleDefines the style attribute.
Style Sheet ModuleDefines the style element.
Tables ModuleDefines the elements used in tables.
Target ModuleDefines the target attribute.
Text ModuleDefines text container elements like p and h1.

* Deprecated elements should not be used in XHTML.

Module nameDescription
Applet ModuleDefines the deprecated* applet element.
Base ModuleDefines the base element.
Basic Forms ModuleDefines the basic forms elements.
Basic Tables ModuleDefines the basic table elements.
Bi-directional Text ModuleDefines the bdo element.
Client Image Map ModuleDefines browser side image map elements.
Edit ModuleDefines the editing elements del and ins.
Forms ModuleDefines all elements used in forms.
Frames ModuleDefines the frameset elements.
Hypertext ModuleDefines the a element.
Iframe ModuleDefines the iframe element.
Image ModuleDefines the img element.
Intrinsic Events ModuleDefines event attributes like onblur and onchange.
Legacy ModuleDefines deprecated* elements and attributes.
Link ModuleDefines the link element.
List ModuleDefines the list elements ol, li, ul, dd, dt, and dl.
Metainformation ModuleDefines the meta element.
Name Identification ModuleDefines the deprecated* name attribute.
Object ModuleDefines the object and param elements.
Presentation ModuleDefines presentation elements like b and i.
Scripting ModuleDefines the script and noscript elements.
Server Image Map ModuleDefines server side image map elements.
Structure ModuleDefines the elements html, head, title and body.
Style Attribute ModuleDefines the style attribute.
Style Sheet ModuleDefines the style element.
Tables ModuleDefines the elements used in tables.
Target ModuleDefines the target attribute.
Text ModuleDefines text container elements like p and h1.

* Deprecated elements should not be used in XHTML.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值