您的位置:首页技术开发ASP技巧 → 在JSP、ASP和PHP网站网页中使用XHTML

在JSP、ASP和PHP网站网页中使用XHTML

时间:2004/11/7 4:10:00来源:本站整理作者:蓝点我要评论(0)

Overview



A wise programmer once said, "The one constant in computing is change." There couldn't be a truer

statement. This article is about such change, specifically moving from HTML to the next generation, XHTML

(Extensible Hypertext Markup Language).



This article includes the following sections:



An Introduction to XHTML

Implementing XHTML Today

Changing HTML to XHTML

Conclusion

Additional XHTML Resources and Facts

The analysis is from a server-side perspective, meaning it applies equally well to ASP, JSP, PHP or other

server-side driven projects.







An Introduction to XHTML



XHTML (now in version 1.1) is the merging of HTML 4 and XML. It represents such an important advancement

that the World Wide Web Consortium (W3C), the international standards body for the web, is replacing HTML

with XHTML as the standard tool for creating web pages.



XHTML is built to open doors to other formats. For example, XHTML can be used to format content for

pagers, whereas HTML cannot. XHTML will replace WAP and other markup languages. It is a cornerstone in the

revolutionary change in thinking beginning to occur in web site design. Instead of viewing a web site as a

stand alone data island, XHTML will expand web applications, allowing web sites to control and send

information which will drive countless devices, presentation styles and other web sites. XHTML is the

starting point for this tremendous change we are about to experience in how we use the web.



Using XHTML has many advantages over using HTML. Because of its structure, XHTML is faster. Its well

formed documents result in quicker and smaller parsers. These smaller parsers waste less time verifying

and doing logic sorting that's required for hodge podge HTML documents. While faster results are not

available yet, expect improved performance from the next generation of XHTML-based browsers.



The architecture of XHTML allows tags, attributes and document types to be uniquely defined by the users

of XHTML. HTML restrictions no longer apply. Over time, this will allow for the development of industry

and project specific XHTML documents. To explore this idea more fully, see the W3C page.



A significant limitation of HTML today is the form field. The W3C established special task groups to

expand the functionality of XHTML and one of these is working to improve form field usage. The

XHTML/XForms specifications are still under development but when done will dramatically change the way we

use forms. A list of some of the great features XForms will add includes:



Pre-built functions remove the need to use JavaScript as heavily as in the past. It will be a great boon

for supporting small devices where JavaScript may not have been available.

Elements are device independent, allowing flexibility to add voice or other input methods.

Data is transmitted from the form in XML format.

Data types are predefined.

Forms will be separated into 3 distinct layers: presentation, logic and data. Splitting forms into these

logical partitions will make it easy for forms to work on different kinds of browsers and devices while

maintaining a standard back end.

What other advancements does the future hold for forms? Only the final specifications will tell the full

story on all the features. The draft specifications for XForms were released in April 2000. The final

specifications are expected by year end. XForms will likely be one of the driving forces to upgrade to

XHTML in the future. For more information on XForms see W3C and W3schools.



Another advantage of XHTML is that it is a XML-based system. XML is an great technology and it is being

used in many exciting ways. While programmers would like to use XML in a variety of applications, it still

isn't practical to use for many projects. XHTML changes this because it makes XML easy to use with any

project. Learning XHTML means expanding XML knowledge and skills. It means learning to think in XML. XHTML

enables sites to use XML conveniently in day-to-day web business. It is the stepping stone that will

finally give everyone easy access to the power and convince of XML.



Implementing XHTML Today



How soon does XHTML need to be implemented? That depends on a number of factors, many of them

infrastructure related. The current generation of tools, such as editors and browsers, need updating to

use XHTML efficiently and smoothly. Then these updated tools need to make their way into common use.

Furthermore, some of the standards, like XForms, are still under development, and once developed will

likely change (much like any new software) soon after the first full release. Addressing these

infrastructure issues will likely take from one to four years.



Nothing, however, is stopping conversion from beginning now, and, in fact, it's a good idea to start

learning the basics of XHTML, incorporating it into current projects and planning for it in new projects.

It's a good time to begin changing programming habits to enable a smooth transition in the future. This is

possible for a few reasons.



For the most part, XHTML content which doesn't match standard HTML will still usually work with HTML

parsers. This is because the parsers ignore most errors. When a parser encounters something that isn't

quite right in the page it usually won't cause a failure. This isn't always true, such as for scripting

(discussed below), but it is possible to at least make most end pages of projects completely XHTML

compliant.



As another example, because XHTML is case sensitive, tags are written in lower case. While this may seem

like a relatively minor change, it is one, none the less, which can be implemented immediately, creating a

good programming habit. Similarly, nesting rules are strict in XHTML and can be followed in HTML to

ingrain good programming habits. Both of these topics are discussed more below.



Implementing XHTML in HTML web applications now also helps ensure that the output will be XHTML compatible

later. Designing with an eye to the future is important whether that future be 6 months or 10 years from

now. Changing a web page is easy, but updating the components takes more thought and time.



How do you implement a migration plan? Begin to write code which is XHTML compliant but don't require the

end pages to be completely compliant at this stage. You may find you need to make significant changes in

how your dynamic server pages are written. If you use code from your library, make sure XHTML rather than

HTML is being produced. When the HTML pages are done with the components integrated, run them through a

conversion tool to update them and check for IDE-generated HTML that doesn't match the XHTML standard.

That's it! Just remember, the goal isn't necessarily to be 100% XHTML compliant, but rather to begin

learning and applying XHTML where it makes sense for your projects and web sites. It can be applied in

stages, so take advantage of this flexibility where it benefits you.



Changing HTML to XHTML



Here's some of the particulars you should consider in getting started with your conversion from HTML to

XHTML. This isn't a comprehensive list or discussion, but covers the major changes using the strict

document definition.



XHTML is based on XML standards. This means a document must follow "well formed" rules, that is, XML

syntax. The rules of most concern include:



XML is case sensitive. In XHTML this means every HTML tag must be written in lower case. So use

not
. Current HTML editing tools will fight you here. Don't worry about the case that is auto-

generated. Instead, when hand typing in HTML tags, get used to using lower case. Also, when generating

HTML dynamically make sure to use lower case.



IMPORTANT! While your should get use to writing your tags in lower case, don't worry about the case of

HTML tags that are automatically generated by the current generation of HTML editors. Tools are available

to clean up HTML pages to make them XHTML compliant. These tools, however, will not catch tags with

improper syntax generated by your code! Get in the habit of using the right syntax within your scriptlets,

JavaBeans, Com objects or wherever else you are generating your own HTML content.





Non-empty tags must be properly nested. This means tags do not cross over each other. In the invalid

example below notice that the form and table tags are improperly nested, that is, they cross over one

another. Then see how this is rectified in the correct example. Invalid Example:







hi







Correct Example:







hi


  





Attribute values must be quoted. So
is not legal but is

legal.





All tags must be closed. For tags which don't normally have a closing element, end the tag within itself.

For example,
by itself is not legal. Rather, use
. These tags may also end like
, but


syntax seems to work better with current browsers.





No attribute may appear more than once in the same tag. This shouldn't be a problem.



In addition to the changes driven by XML, more changes in tags are driven by XHTML's own DTD (document

type definition). Here's the highlights.

The first tag in a XHTML document must be . 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:







When writing for the most HTML compatibility use the transitional DTD :







When using frames use the frameset DTD:







The transitional DTD will be used for most pages.





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





The tag is mandatory in a XHTML document. <br><BR> <br><BR> <br><BR> Form tags must have an action attribute. For example, <form action="test.htm"></form><br><BR> <br><BR> <br><BR> Style tags such as <font> and <center> have been removed! Use style sheets for formatting.<br><BR> <br><BR> <br><BR> Data (which in a HTML page would be text) must be enclosed within a set of valid tags. A partial list of <br><BR> valid tags to enclose free standing data (text) includes "p", "h1" "div", "pre". <br><BR> <br><BR> The first example is wrong because the data (text) is not enclosed within a defined tag set<br><BR> <body><br><BR> HI, this is Wrong.<br><BR> <br/><br><BR> <a href="http://validator.w3.org/check/referrer" rel="nofollow">validate</a><br><BR> </body><br><BR> <br><BR> This is the correct way to include data using the div tag.<br><BR> <body><br><BR> <div><br><BR> HI, this is Right.<br><BR> <br/><br><BR> <a href="http://validator.w3.org/check/referrer" rel="nofollow">validate</a><br><BR> </div><br><BR> </body><br><BR> <br><BR> <br><BR> <br><BR> Every <img> tag must have an alt attribute. <br><BR> <br><BR> <br><BR> Every <style> tag must have a type attribute. <br><BR> <br><BR> <br><BR> No stand-alone attributes (also known as minimized attributes) are allowed. For example, <option selected> <br><BR> is no longer valid. Instead, it will look like <option selected="selected">.<br><BR> <br><BR> <br><BR> "Inline" tags cannot contain "block-level" tags. For example, an anchor tag can't enclose a <table><br><BR> <br><BR> <br><BR> Scripting elements pose a problem for XHTML compatibility. The XML parser will parse the script as a XML <br><BR> document unless you enclose your script in a CDATA block. Therefore, a JavaScript element would now look <br><BR> like:<br><BR> <br><BR> <script type="text/javascript"><br><BR> <![CDATA[ alert("hello"); ]]><br><BR> </script><br><BR> <br><BR> <br><BR> This causes a hassle for all the current browsers as they will not like the CDATA block. For now, the only <br><BR> solution is to call the JavaScript from an external file. For example:<br><BR> <br><BR> <script language="JavaScript" type="text/javascript" src="main.js"></script>  <br><BR> <br><BR> For the server-side programmer this is a problem when you modify the JavaScript dynamically. Using a <br><BR> separate file source for your JavaScript prevents you from being able to dynamically change your <br><BR> JavaScript. This is because the JavaScript is being included on the client side so the server side won't <br><BR> be able to touch it now. When modifying JavaScript using ASP, JSP or PHP scripting, use the standard HTML <br><BR> method of script declaration. This is the one place where making JSP or ASP 100% compatible with XHTML <br><BR> will be most problematic. Remember, however, the goal is not to be 100% compatible with XHTML, but to <br><BR> begin incorporating XHTML where feasible, allowing a quick and easy transition when the time comes. When <br><BR> that time arrives, new compatible browsers should be available and you'll be set to make the jump to 100% <br><BR> compatibility. <br><BR> Conclusion<br><BR> <br><BR> In this article we've explored some advantages of XHTML and how to start using it right now with very <br><BR> little hassle. XHTML is far more than a replacement for HTML. Thinking of it as HTML 5.0 unnecessarily <br><BR> limits its power and the possibilities it will introduce. XHTML is meant to be expanded by the user <br><BR> community. It creates XML documents which contain, define and manipulate data, going far beyond the <br><BR> capabilities of HTML-based documents. It makes XML easy to use. To fully realize the potential XHTML <br><BR> presents will require a new way of thinking about future applications. It creates fresh possibilities. <br><BR> XHTML really is a new thing (not merely an upgrade) and the challenge ahead of us is to experiment and <br><BR> discover where it can take us. <br><BR> <br><BR> <br><BR> <br><BR> <br><BR> </span> <BR> </dd> </dl> <div id="xgsp"><p class="tit"><em>相关视频</em></p> <div class="sp-wrap"> <ul class="clearfix"> <li><a href="/video/35627.html" target="_blank"><img src="http://thumb.jfcdns.com/n131f33y14414/7ef6220197161773.jpeg"><span>windows10自带扫雷游戏在哪</span></a></li><li><a href="/video/35608.html" target="_blank"><img src="http://thumb12.jfcdns.com/n331r1933t6b14n1e13/7ef621f2e386e59b.jpeg"><span>windows11专业版和家庭版的区别</span></a></li><li><a href="/video/35609.html" target="_blank"><img src="http://thumb.jfcdns.com/n3319v533e4014eln13/7ef621f2ef964d53.jpeg"><span>windows11家庭版和专业版有什么区别</span></a></li><li><a href="/video/35470.html" target="_blank"><img src="http://thumb2.jfcdns.com/n3315vb331dh13emv38/7ef621b17fd6b5e5.jpeg"><span>windows11我的电脑在哪里打开</span></a></li><li><a href="/video/35469.html" target="_blank"><img src="http://thumb12.jfcdns.com/n3313eu3330g1365f38/7ef621b16c26f688.jpeg"><span>windows11我的电脑在哪</span></a></li><li><a href="/video/35466.html" target="_blank"><img src="http://thumb10.jfcdns.com/n331xf6331dy13drs38/7ef621b10e146fcf.jpeg"><span>win11系统怎么退出微软账号</span></a></li><li><a href="/video/35091.html" target="_blank"><img src="http://thumb10.jfcdns.com/n231sp33cd134j22/7ef62061e5f02b61.jpeg"><span>win10ie打开变成edge</span></a></li><li><a href="/video/34798.html" target="_blank"><img src="http://thumb10.jfcdns.com/n331zf433u2x1212t36/7ef61efa5c1e0e6e.jpeg"><span>win11怎么设置默认浏览器</span></a></li><li><a href="/video/34683.html" target="_blank"><img src="http://thumb11.jfcdns.com/n2317533wl12ji32/7ef61ea73b416974.jpeg"><span>win11 ie浏览器在哪里</span></a></li><li><a href="/video/34071.html" target="_blank"><img src="http://thumb10.jfcdns.com/n131032w23h42/7ef61ce5b1bddfd3.jpeg"><span>windows11怎么连接wifi</span></a></li><li><a href="/video/34070.html" target="_blank"><img src="http://thumb10.jfcdns.com/n131q32823t42/7ef61ce5a5e38c81.jpeg"><span>windows11有必要升级吗</span></a></li><li><a href="/video/34069.html" target="_blank"><img src="http://thumb10.jfcdns.com/n131632l23o42/7ef61ce59b2d938d.jpeg"><span>windows11怎么把我的电脑放在桌面上</span></a></li><li><a href="/video/33644.html" target="_blank"><img src="http://thumb1.jfcdns.com/n331j1l32yg223ums26/7ef61b9add7dbd37.jpeg"><span>win10怎么隐藏任务栏</span></a></li><li><a href="/video/33524.html" target="_blank"><img src="http://thumb2.jfcdns.com/n331g1e3240e23utf23/7ef61b5b9fbe02f8.jpeg"><span>win10任务栏颜色怎么改</span></a></li><li><a href="/video/33520.html" target="_blank"><img src="http://thumb11.jfcdns.com/n331n4m32waz23w6023/7ef61b5b5c19d8a4.jpeg"><span>win10已禁用输入法怎么解决</span></a></li> </ul> </div> </div> <p id="lread"> <b class="tit"><em>相关阅读</em></b> <span> <i><a href="/infoview/Article_181275.html">Windows错误代码大全 Windows错误代码查询</a></i><i><a href="/edu/180591.html">激活windows有什么用</a></i><i><a href="/edu/142370.html">Mac QQ和Windows QQ聊天记录怎么合并 Mac QQ和Windows QQ聊天记录</a></i><i><a href="/infoview/Article_140347.html">Windows 10自动更新怎么关闭 如何关闭Windows 10自动更新</a></i><i><a href="/infoview/Article_136060.html">windows 10 rs4快速预览版17017下载错误问题</a></i><i><a href="/infoview/Article_133896.html">Win10秋季创意者更新16291更新了什么 win10 16291更新内容</a></i><i><a href="/infoview/Article_131339.html">windows10秋季创意者更新时间 windows10秋季创意者更新内容</a></i><i><a href="/infoview/Article_118674.html">kb3150513补丁更新了什么 Windows 10补丁kb3150513是什么</a></i> </span> </p> <dl id="commentBox"><dt class="tit"><i>文章评论</i></dt> <dd id="comment"> <div id="comment-list"> <div id="hotCmt"> </div> <dl> </dl> <p id="cmtNum-wrap"><a href="/comment_29487_1.html">查看所有<span id="cmtNum">0</span>条评论>></a></p> </div> <div id="comment-form"> <form action="/ajax.asp" method="post" id="cmtForm"> <fieldset> <legend>发表评论</legend> <input name="SoftID" type="hidden" id="softID" value="29487" /> <input name="CommentTpye" type="hidden" value="1" /> <input name="Action" type="hidden" value="2" /> <p id="userName-wrap"><input name="UserName" type="text" id="userName" class="input-bg grey9" maxLength="10" value="PC6网友" /></p> <p><textarea name="content" id="cmtMsg" class="input-bor">我来说两句...</textarea></p> <p><button type="submit" class="btn-submit button btnOrg fr" id="subCmt">提交评论</button></p> </fieldset> </form> </div> </dd><!-- #comment end --> </dl> </dt> <dd id="cside"> <div class="adr"></div> <p id="rpj"> <b class="tit"><em>热门文章</em></b> <span> 没有查询到任何记录。 </span> </p> <p id="wj"> <b class="tit"><em>最新文章</em></b> <span> <i><a href="/infoview/Article_38559.html"><img src="/uploadimages/200971082951352.jpg" /><b>VB.NET 2005编写定时关</b></a></i> </span> <s> <a href="/infoview/Article_49710.html" target="_blank">Jquery get/post下乱码解决方法 前台gbk gb</a><a href="/infoview/Article_43548.html" target="_blank">如何使用数据绑定控件显示数据</a><a href="/infoview/Article_43547.html" target="_blank">ASP脚本循环语句</a><a href="/infoview/Article_43546.html" target="_blank">ASP怎么提速</a> </s> </p> <p id="rwz"> <b class="tit"><em>人气排行</em></b> <span> <i><a href="/infoview/Article_52974.html" target="_blank">轻松解决"Server Application Error"和iis"</a></i><i><a href="/infoview/Article_50411.html" target="_blank">一起学习DataGridView调整列宽</a></i><i><a href="/infoview/Article_29844.html" target="_blank">用ASP随机生成文件名的函数</a></i><i><a href="/infoview/Article_49710.html" target="_blank">Jquery get/post下乱码解决方法 前台gbk gb</a></i><i><a href="/infoview/Article_29519.html" target="_blank">ODBC Drivers错误80004005的解决办法</a></i><i><a href="/infoview/Article_29682.html" target="_blank">返回UPDATE SQL语句所影响的行数的方法</a></i><i><a href="/infoview/Article_29533.html" target="_blank">用Javascript隐藏超级链接的真实地址</a></i><i><a href="/infoview/Article_29880.html" target="_blank">两个不同数据库表的分页显示解决方案</a></i> </span> </p> </dd> </dl> <!--#include virtual="/include/footer/news_footer.html"--> <script type="text/javascript"> var _webInfo = {};_webInfo={Username:"网络虫虫",Type:"1",DateTime:"2004/11/7 4:10:00",Id:"29487"};</script> <script type="text/javascript" src="http://www.a300.cn/inc/jquery-1.4.2.min.js"></script> <script type="text/javascript" src="http://www.a300.cn/js/nwz.js"></script> <script type="text/javascript"> var pageClass=7; //读取文章人气 ViewCmsHits('hits',29487); $("#comment-list > dl > dd > p a:last-child").addClass("glBtn"); BindDing("#comment-list > dl > dd > p",29487,1);//顶 </script> <script type="application/ld+json"> { "@context": "http://zhanzhang.baidu.com/contexts/cambrian.jsonld", "@id": "http://www.a300.cn/infoview/Article_29487.html", "title": "在JSP、ASP和PHP网站网页中使用XHTML _pc6资讯", "description": ",在JSP、ASP和PHP网站网页中使用XHTML", "pubDate": "2004-11-07T04:10:00", "upDate": "2004-11-07T04:10:00", "data":{ "WebPage":{ "pcUrl":"http://www.a300.cn/infoview/Article_29487.html", "wapUrl":"http://m.a300.cn/n/29487", "fromSrc":"pc6下载站" } } } </script> </body> </html>