原文地址:http://www.w3schools.com/xhtml/xhtml_howto.asp
翻译:范维肖
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代码的。
本文地址:http://com.8s8s.com/it/it30939.htm