Use XHTML in JSP, ASP, and PHP Web pages

Source: Internet
Author: User
Tags definition cdata final html page html tags include valid xml parser
Overview

A wise programmer once said, "the one constant in computing be change." There couldn ' t be a truer
Statement. This article are about such change, specifically moving from HTML to 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 are from a server-side perspective, meaning it applies equally down to ASP, JSPs, 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's the World Wide Web Consortium, the international standards to the Web, is replacing HTML
With XHTML as the standard tool for creating Web pages.

The XHTML is built to open doors to the other formats. For example, XHTML can is used to format content for
Pagers, whereas HTML cannot. XHTML would 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 would expand Web applications, allowing Web sites to control and send
Information which'll 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.

The using XHTML has many advantages over using HTML. Because of its structure, the XHTML is faster. Its
Formed documents 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
Available yet, expect improved performance from the next generation of xhtml-based.

The architecture of XHTML allows tags, attributes and document types to is uniquely defined by the users
of XHTML. HTML restrictions no longer apply. Over time, this'll allow for the development of industry
and project specific XHTML documents. To explore this idea for more fully

A Significant limitation of HTML today is the form field. The consortium established special task groups to
Expand the functionality of XHTML and one of these are working to improve form field usage. The
Xhtml/xforms specifications are still under development when do would but change the dramatically we
Use forms. A List of some of the great features XForms would add includes:

Pre-built functions remove the need to use JavaScript as heavily as in the past. It'll be a great boon
For supporting small devices where JavaScript to not have been available.
Elements are device independent, allowing flexibility to add voice or other input methods.
The Data is transmitted to the form in XML format.
Data types are predefined.
Forms'll is separated into 3 distinct layers:presentation, logic and data. Splitting forms into these
Logical partitions'll make it easy for forms to work on different kinds of browsers and devices while
Maintaining a standard back end.
What advancements does the future hold for forms? Only the final specifications'll tell the full
Story on the "All" features. The draft specifications for XForms were released in April 2000. The final
Specifications are expected by the year end. XForms would likely be one of the ' driving forces to upgrade to
XHTML in the future. For more information on XForms, and W3Schools.

Another advantage of XHTML is-it is-a xml-based system. XML is a great technology and it is being
Used in many exciting ways. While programmers would-like-use XML in a variety of applications, it still
Isn ' t practical to use for many projects. XHTML changes This is because it makes XML easy to use and any
Project. Learning XHTML means expanding XML knowledge and skills. It means learning to the in XML. Xhtml
Enables sites to use XML conveniently in day-to-day web business. It is the stepping stone that would
Finally give everyone easy access to the power and convince of XML.

Implementing XHTML Today

How soon does XHTML need to is implemented? That is 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 would
Likely change (more like any new software) soon after the "the" Addressing
Infrastructure issues'll likely take from one to four years.

Nothing, however, are stopping conversion from beginning now, and, in fact, it's a good idea to start
Learning the basics of XHTML, incorporating it into the 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 would still usually 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 and such as for scripting
(discussed below), but it are possible to in 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 of the less, which can be implemented immediately, creating a
Good programming habit. Similarly, nesting rules are strict in XHTML and can is followed in HTML to
Ingrain good programming habits. Both of topics are discussed more below.

Implementing XHTML in HTML Web applications now also helps ensure that the output would be XHTML compatible
Later. Designing with a eye to the future is important whether then future be 6 months or ten years from
Now. Changing a Web page is easy, but updating the components takes more thought and time.

Implement a migration plan? Begin to write code which is XHTML compliant but don ' t require the
End pages to is completely compliant at this stage. You could find your need to make significant changes in
How your dynamic server Pages are written. If You use the code from your library, make sure XHTML rather than
HTML is being produced. When the HTML pages are do 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 is 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 the 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.

The XHTML is based on XML standards. This means a document must follow "OK formed" rules, which is, XML
Syntax. The rules of most concern include:

XML is case sensitive. In XHTML This means every HTML tag must is written in lower case. So use <table>
Not <table>. Current HTML editing tools would fight you. Don ' t worry about the case this is auto-
Generated. Instead, when the hand typing in HTML tags, get used to using the lower case. Also, when generating
HTML dynamically make sure to use lower case.

important! While your should get-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, won't catch tags with
Improper syntax generated by your code! Get in the habit by using the right syntax within your scriptlets,
JavaBeans, Com objects or wherever else you are generating your HTML content.


Non-empty tags must be properly nested. This means tags don't cross over each of the other. In the invalid
Example below notice that the form and table tags are improperly nested, which, they cross over one
Another. Then is rectified to the correct example. Invalid Example:
<form action= "Test.htm" >
<table>
<tr><td>hi
</form>
</td></tr>
</table>

Correct Example:
<form action= "Test.htm" >
<table>
<tr><td>hi</td></tr>
</table>
</form>


Attribute values must be quoted. So <form action=test.htm> are not legal but <form action= ' test.htm ' > is
Legal.


All tags must be closed. For tags which don ' t normally have a closing element, end the tag within itself.
For example <br> by itself isn't legal. rather, use <br/>. These tags may also end like </br>, but
<br/> syntax seems to work better with the current browsers.


No attribute may appear more than once in the same tag. This is 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 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 to 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 the frameset DTD:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 frameset//en" "Dtd/xhtml1-frameset.dtd" >


The transitional DTD is used for most pages.


The second tag in a XHTML document must the "

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> <center> have been removed! Use style sheets for formatting.


Data (which in a HTML page would is 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 The example is wrong because the data (text) are 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 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 would 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 would parse the script as a XML
Document unless you enclose your script in a CDATA blocks. Therefore, a JAVASCRIPT element would now look
Like

<script type= "Text/javascript" >
<! [cdata[alert ("Hello");]] >
</script>


This causes a hassle to all is the current browsers as they won't as the CDATA block. For now, the only
Solution is to call the JavaScript from a external file. For example:

<script language= "JavaScript" type= "Text/javascript" src= "Main.js" ></script>

For the Server-side programmer the "is a problem" you modify the JavaScript dynamically. Using A
Separate file source for your JavaScript prevents your from being able to dynamically change your
Javascript. This is because the JavaScript was being included on the client side so the server side won ' t
Be able into 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
would be most problematic. Remember, however, the goal is isn't to being 100% compatible with XHTML, but to
Begin incorporating XHTML where feasible, allowing a quick and easy transition when the time comes. When
This time arrives, new compatible browsers should is 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 the to-start using it right now with very
Little hassle. The XHTML is far the more than a replacement for HTML. Thinking of it as HTML 5.0 unnecessarily
Limits its and the possibilities it'll introduce. XHTML is meant to being 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 would require a new way of thinking about future applications. It creates fresh possibilities.
XHTML really is a new thing (not merely a upgrade) and the challenge ahead of ' US ' to experiment and
Discover where it can take us.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.