怎样转换成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
添加DOCTYPE定义
The following DOCTYPE declaration was added as the first line of every page:
在每个页的首行添加如下DOCTYPE声明:
<!DOCTYPE html PUBLIC |
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.
注意我们使用的是过渡型的DTD。我们可以选择严密型的 DTD,但它的要求有点过于严格,想完全地去遵循它有些困难。
A Note About The DOCTYPE
有关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区分大小写并只接受小写HTML标签和属性后,查找所有大写标签并替换成小写标签的工作开始了。对那些属性名称也是这样。如在代码书写中已经习惯使用小写属性名称那这类工作实际上量度并不大。
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.
W3C 表示XHTML1.0中所有属性值都必须被引号括起来,所以每个页都需要检查,这是项消耗时间的工作,以后应该避免出现这类问题。
Empty Tags: <hr> , <br> and <img>
空标签: <hr> , <br> 和 <img>
Empty tags are not allowed in XHTML. The <hr> and <br> tags should be replaced with <hr /> and <br />.
在XHTML中不允许有空标签.像<hr>和<br>应该用<hr />和<br />来替换
This produced a problem with Netscape that misinterpreted the <br/> tag. 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.
用<br/>标签的话会在网景浏览器中出现错误。我们不需要知道为什么会出现错误,使用<br />来解决这个问题(br后多加个空格)。
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.
一些其它的标签(像<img>标签)会出现像上面一样的问题.不要用</img>来关闭<img>标签,可以通过标签的末尾使用 /> 来解决。
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.
以上任务完成后,所有的页需经过这条连接来通过W3C官方的校验: XHTML Validator