Use XHTML in JSP, ASP, and PHP Web pages

Source: Internet
Author: User
Tags cdata xml parser
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 functions des 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
Pagers, whereas HTML cannot. XHTML will replace WAP and other markup ages. It is a cornerstone in
Revolutionary change in thinking beginning to occur in web site design. Instead of viewing a web site as
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
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 statements. While faster results are not
Available yet, Except CT 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 define e this idea more fully, see the W3C page.

A significant limitation of HTML today is the form field. The W3C established special task groups
Expand the functionality of XHTML and one of these is working to improve form field usage.
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 schemdes:

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 each l 2000. The final
Specifications are expected by year end. XForms will likely be one of the driving forces to upgrade
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 advance exciting ways. While programmers wocould like to use XML in a variety of applications, it still
Isn' t practical to use for temporary 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, role of them
Infrastructure related. The current generation of tools, such as editors and browsers, need updating
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, inconfigurating 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
Good Programming habit. Similarly, nesting rules are strict in XHTML and can be followed in HTML
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
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
HTML is being produced. When the HTML pages are done with the components integrated, run them through
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 participating ARS you shoshould consider in getting started with your conversion from HTML
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 shocould get use to writing your tags in lower case, don't worry about the case
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
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:

??

Attribute values must be quoted. So

Style tags such as and have been removed! Use style sheets for formatting.

Data (which in a HTML page wocould be text) must be enclosed within a set of valid tags. A partial list
Valid tags to enclose free standing data (text) between des "P", "h1" "Div", "pre ".

The first example is wrong because the data (text) is not enclosed within a defined tag set

Hi, this is wrong.

Validate

This is the correct way to include data using the DIV tag.


Hi, this is right.

Validate

Every tag must have an ALT attribute.

Every tag must have a type attribute.

No stand-alone attributes (also known as minimized attributes) are allowed. For example,
Is no longer valid. Instead, it will look like.

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

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 wocould now look
Like:

This causes a hassystemic 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:

??

For the server-side programmer this is a problem when you modify the Javascript dynamically. Using
Separate file source for your JavaScript prevents you from being able to dynamically change your
Javascript. This is because the Javascript is being encoded 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
Begin inconfigurating XHTML where feasible, allowing a quick and easy transition when the time comes. When
That time arrives, new compatible browsers shocould be available and you'll be set to make the jump to 100%
Compatibility.
Conclusion

In this article we 've got ed some advantages of XHTML and how to start using it right now with very
Little hassystemic. 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 ents which contain, define and manipulate data, going far beyond
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.

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.