您现在的位置: 军旅同心-旅游自驾-军旅文学 >> 读书赏析 >> 学习园地 >> 电脑网络 >> 技术文章 >> 正文
在JSP、ASP和PHP网站网页中使用XHTML
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005-9-10 14:20:07
n). Here's the highlights.
The first tag in a XHTML document must be <!DOCTYPE>. This tag informs the reader which definition to use
in describing the XHTML document. XHTML uses DTD modules to translate tags. In selecting among the three
DTDs follow these rules.


When writing pure XHTML use the strict DTD:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">


When writing for the most HTML compatibility use the transitional DTD :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">


When using frames use the frameset DTD:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "DTD/xhtml1-frameset.dtd">


The transitional DTD will be used for most pages.


The second tag in a XHTML document must be <html> and the xmlns attribute is mandatory.


The <title> tag is mandatory in a XHTML document.


Form tags must have an action attribute. For example, <form action="test.htm"></form>


Style tags such as <font> and <center> have been removed! Use style sheets for formatting.


Data (which in a HTML page would be text) must be enclosed within a set of valid tags. A partial list of
valid tags to enclose free standing data (text) includes "p", "h1" "div", "pre".

The first example is wrong because the data (text) is not enclosed within a defined tag set
<body>
HI, this is Wrong.
<br/>
<a href="http://validator.w3.org/check/referrer">validate</a>
</body>

This is the correct way to include data using the div tag.
<body>
<div>
HI, this is Right.
<br/>
<a href="http://validator.w3.org/check/referrer">validate</a>
</div>
</body>



Every <img> tag must have an alt attribute.


Every <style> tag must have a type attribute.


No stand-alone attributes (also known as minimized attributes) are allowed. For example, <option selected>
is no longer valid. Instead, it will look like <option selected="selected">.


"Inline" tags cannot contain "block-level" tags. For example, an anchor tag can't enclose a <table>


Scripting elements pose a problem for XHTML compatibility. The XML parser will parse the script as a XML
document unless you enclose your script in a CDATA block. Therefore, a JavaScript element would now look
like:

<script type="text/javascript">
<![CDATA[ alert("hello"); ]]>
</script>


This causes a hassle for all the current browsers as they will not like the CDATA block. For now, the only
solution is to call the JavaScript from an external file. For example:

<script language="JavaScript" type="text/javascript" src="main.js"></script>  

For the server-side programmer this is a problem when you modify the JavaScript dynamically. Using a
separate file source for your JavaScript prevents you from being able to dynamically change your
JavaScript. This is because the JavaScript is being included on the client side so the server side won't
be able to touch it now. When modifying JavaScript using ASP, JSP or PHP scripting, use the standard HTML
method of script declaration. This is the one place where making JSP or ASP 100% compatible with XHTML
will be most problematic. Remember, however, the goal is not to be 100% compatible with XHTML, but to
begin incorporating XHTML where feasible, allowing a quick and easy transition when the time comes. When
that time arrives, new compatible browsers should be available and you'll be set to make the jump to 100%
compatibility.
Conclusion

In this article we've explored some advantages of XHTML and how to start using it right now with very
little hassle. XHTML is far more than a replacement for HTML. Thinking of it as HTML 5.0 unnecessarily
limits its power and the possibilities it will introduce. XHTML is meant to be expanded by the user
community. It creates XML documents which contain, define and manipulate data, going far beyond the
capabilities of HTML-based documents. It makes XML easy to use. To fully realize the potential XHTML
presents will require a new way of thinking about future applications. It creates fresh possibilities.
XHTML really is a new thing (not merely an upgrade) and the challenge ahead of us is to experiment and
discover where it can take us.




上一页  [1] [2] 


更多
免责声明:作品版权归所属媒体与作者所有!!本站刊载此文不代表同意其说法或描述,仅为提供更多信息。如果您认为我们侵犯了您的版权,请告知!本站立即删除。有异议请联系我们。
文章录入:烟灰缸    责任编辑:烟灰缸 
网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
| 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 网站地图 | 版权申明 | 网站公告 | 管理登录 |