Need some clarifications on xhtml

T

Thierry Lam

I've decided to switch to xhtml and I've added the following at the top
of my page:

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">


However, my page is still working and I can't see any warnings whenever
I use old html tags like <br> instead of <br/>. What other things
should I add to validate xhtml tags?
 
J

jojo

Thierry said:
I've decided to switch to xhtml and I've added the following at the top
of my page:
Why?


<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

Where do you expect the warnings to appear? Definetly not in the
browser... (except you use some firefox extension or something similar)
However, my page is still working and I can't see any warnings whenever
I use old html tags like <br> instead of <br/>. What other things
should I add to validate xhtml tags?

A XHTML document should look like this:

<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- page head -->
</head>
<body>
<!-- page body -->
</body>
</html>
 
C

cwdjrxyz

Thierry said:
I've decided to switch to xhtml and I've added the following at the top
of my page:

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">


However, my page is still working and I can't see any warnings whenever
I use old html tags like <br> instead of <br/>. What other things
should I add to validate xhtml tags?

Go to http://validator.w3.org/ to validate a page as any of several
forms of html/xhtml including the one you mention. The break tag you
mention usually is written with a space included in it as <br />. I
believe this was done to avoid problems with some browsers. In general
all tags have to be closed in xhtml. When tags such as br and img that
have no close tag in html are used they most be closed as was done for
br above such as <img blah />. Closing p is optional in html. In xhtml
a paragraph must always use a closing tag </p> in addition to the
opening tag <p>. Unless you set up your server to serve true xhtml
using an extension such as xhtml and associating a mime type with it
such as xhtml+xml, the page will just be served as text/html despite
your xhtml tags and Doctype. Note the page will still validate as xhtml
if there are no errors. The validator just checks the code for what you
ask. However if you use the advanced interface to validate, there will
be additional information showing you how the page is served. Recent
Firefox, Netscape, Opera, and a few other browsers can handle xhtml
served correctly as such. However IE6 will not, and you can not view
the page. You have to provide IE6 and a few older browsers with an html
4.01 strict page using some server side code or whatever to allow
viewing of the page by them. Unless you do all of this, there is no
point in writing the page in xhtml if IE6 and some older browsers are
intended to be viewed with it. Unfortunately it appears that not even
IE7 will handle true xhtml. It is quite possible to serve even xhtml
1.1 correctly. However, to do so, you have your work cut out for you
and much to learn, likely including some server side languages.

When a page is properly served as xhtml is viewed with a browser that
can handle it, the browser becomes as strict as a mother superior in a
1800s convent. Tiny code errors that would cause little or no harm on
an html page often cause the browser to give you an error message
rather than a view of the page. Unless one writes very good html 4.01
strict, don't even think of writing xhtml and serving it properly as
such.
 
J

Jukka K. Korpela

Scripsit jojo:

I guess the usual explanation is that people have no idea of XHTML or its
practical usefulness or uselessness, but someone told them it's the "newest
recommendation".
Where do you expect the warnings to appear? Definetly not in the
browser...

Actually, a browser _could_ have a validating XML parser. That was really
more or less part of the idea. Of course, that would not mean warnings but
error messages.
A XHTML document should look like this:

<?xml version="1.0" ?>

Well, in theory it could start with the <?xml ...> declaration, but in
practice, that throws IE to "quirks mode", making it simulate some errors of
IE 5. How modern...
 
D

David Dorward

Well, in theory it could start with the <?xml ...> declaration

.... although it might be forbidden in XHTML documents served as text/html
(its hard to say for sure, the spec is rather fuzzy regarding the subject
and I prefer to avoid it altogether by using HTML 4.01 on the client side
for webpages except where XHTML provides an actual practical benefit).
 
J

jojo

Jukka said:
I guess the usual explanation is that people have no idea of XHTML or
its practical usefulness or uselessness, but someone told them it's the
"newest recommendation".

Yeah, I suppose that's the reason. But unfortunately the "newest" is not
always the best recommendation (Not that the idea behind XHTML is bad,
it's just the poor support in "modern" browsers which is...)
Actually, a browser _could_ have a validating XML parser. That was
really more or less part of the idea. Of course, that would not mean
warnings but error messages.

Right, it could have one. But most browsers have none or do only use it
on properly served XHTML documents (Which means the MIME-type is set to
application/xhtml+xml and not text/html). And I guess the MIME type is
not set properly...
Well, in theory it could start with the <?xml ...> declaration, but in
practice, that throws IE to "quirks mode", making it simulate some
errors of IE 5. How modern...
Oh, yes, I remember... the quirks mode is enabled if there is no Doctype
(with URL, the ones without enable quirks mode ASFAIK) specified in the
*first* line of a html document...

But there maybe is another problem with the xml declaration: if php is
available on the server and short-tags are enabled the <? is recognized
as beginning of a php-statement...
 
T

Toby Inkster

jojo said:
But there maybe is another problem with the xml declaration: if php is
available on the server and short-tags are enabled the <? is recognized
as beginning of a php-statement...

The solution of course is:

<?= '<?xml version="1.0" ?>'."\n" ?>
 
A

Andy Dingley

jojo said:
A XHTML document should look like this:

<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

What's an "XHTML document" ? If you mean a local XML document, then
why not use XHTML 1.1 ? If you mean a web-published document then for
certain you need to lose that XML declaration:

If you're going to pontificate, make sure you're infallible.

Where are the lang and xml:lang attributes ?
 
J

Jukka K. Korpela

Scripsit Andy Dingley:
If you're going to pontificate, make sure you're infallible.

Where are the lang and xml:lang attributes ?

Are _you_ trying to pontificate that the lang and xml:lang attributes are
required? Surely not by the syntax, or by any HTML specifications.

Language markup might good practice, but it has fairly little practical
value. Programs don't use the language information expressed that way very
much, partly because the information is so often plain wrong.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,208
Latest member
RandallLay

Latest Threads

Top