You are here: Re: XHTML or HTML 4 ? « HTML « IT news, forums, messages
Re: XHTML or HTML 4 ?

Posted by cwdjrxyz on 01/13/06 04:29

Marc wrote:
> Which doctype should we be writing to now? What are the advantages /
> disadvantages? I usually write to XHTML1 Strict, but someone in here
> said they don't recommend using XHTML at all... why?

The most important thing is that you use some valid type of html. Even
old 3.2 would serve for very simple pages and is still understood by
most browsers. However it is quite common for many pages from large
corporations to be written in a html soup ranging from html 3.2 to
xhtml levels. Some such pages likely were started many years ago and
just added to by various people over the years. It is no surprise that
some such pages have problems with some common browsers and often fail
and must be patched at new browser upgrades.

Concerning xhtml 1.1, it can be used if you make the effort to learn it
well. At a minimum, in addition to writing valid html 1.1 code, you
must set up your server to serve the page with the mime type of
application/xhtml+xml associated with the extension .xhtml, or you can
also serve as .xml. If you serve a page written in valid xhtml with the
extension .html on most servers, you are just serving the page as html
and might as well use 4.01 strict. When you serve true xhtml 1.1 with
the proper mime type, you will find that it will be viewed well on the
recent Mozilla family browsers(Firefox, Mozilla, and Netscape) and
Opera. There are a few bugs in some browsers that can be overcome, such
as a CSS body background color one on the Mozilla family browsers.
However, IE6 will not display a true xhtml page served correctly, and
rumor has it that neither will the upcoming IE7. You could write a
special page for IE in html 4.01 strict as well as the xhtml 1.1 page.
However, there is a way around this. The server and browser exchange
information when they first connect. The server can ask the browser if
it can handle the correct mime type for true xhtml. This is taken care
of by a php include at the very top of the page that replaces
everything above the head tag of the page, and the page is given an
extension of .php . The include is the same for different pages, so it
is just a 3 line external link to the php code used on all pages. If
the browser likes xhtml, the php on the server writes all of the code
above the head tag required for xhtml 1.1, and that is what you see
when you view the source of the page on a recent Mozilla family or
Opera browser. However, if the browser does not like xhtml, then the
code above the head tag is written as html 4.01 strict, which is what
you see if you view the source of the page on an IE6 and some older
browsers. However, since the page is written for xhtml, everything such
as <br /> must be converted to <br> to satisfy html 4.01 strict. This
is done by a regular expression in the php code. Of course you need to
check the page on IE6 to make certain that the code gets converted
correctly and validates, but you need to check any page on IE6 anyway
as well as on more modern browsers, and it only adds a minute or two to
right click, copy the source, take it to the W3C validator, and paste
it in a text box to validate as html 4.01 strict.

There can be complications if you use some javascript. For example,
document.write is not allowed in xhtml 1.1 and use of it may cause the
page not to display or just give an xml error message. The page is
parsed as xml when you serve it correctly, and there is no telling what
a document.write might generate such as unclosed tags which are fatal
for some xml applications. Thus document.write can not be allowed.
However this can be overcome by writing some of the script in php on
the server which then downloads what the document.write would have
generated on the browser, so the xml parser is happy and can check
everything for closing tags etc.

I have written well over 100 pages in html 1.1 that are served
correctly. Once you have done this several times, it takes very little
more time that using html 4.01 strict, so for me it is no longer a big
deal. My only advice is that if you use xhtml 1.1, do it right. Else
stick with html 4.01 strict.

The reason for xhtml is to make PC html code XML pure. There are now
many other computing devices, and XML has become the standard for
information exchange between them. Xhtml 1.1 greatly improves the XML
purity, but it still does not go quite far enough. The higher levels of
xhtml in the works will require new browsers.

What code you should be using depends on your background and what kind
of pages you write. If you work for someone else, the code you should
use is what they demand, although some bosses are open to suggestion.
If you are your own boss, there are many options. If you are writing
general pages to sell things to a wide variety of people, you usually
can not get too exotic in the code you use. If you are writing for a
network where you can control everything, you can use about any kind of
code you wish. And there are many other levels between these two
extremes.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация