MozillaZine


Firefox and XHTML

Discuss how to use and promote Web standards with the Mozilla Gecko engine.
kenmorgan

User avatar
 
Posts: 152
Joined: February 4th, 2010, 11:15 am

Post Posted January 5th, 2015, 1:33 pm

This post really is about Firefox, so please bear with me! :)

I have created a number of Web sites and have for years believed that it was worth going the "extra mile" to write code to the highest standard possible. I believed this to be the standard for "XHTML 1.0 Strict." My DOCTYPE is:

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


I put all my pages through the W3 Validator and receive this result:

"This document was successfully checked as XHTML 1.0 Strict!"


Recently I was engaged in a conversation on another forum that primarily deals with webmaster coding issues. A particular coding solution to a question I raised was recommended, and I pointed out that, although it would work, it would not pass the Validator as XHTML Strict. One respondent made some rather degrading comments about my attempt to write strict XHTML code:

*All browsers* ignore your XHTML doctype and parse your pages as HTML, not just Firefox.

What you could do is direct your efforts towards things that actually benefit your users, rather than investing time in publishing web pages that almost, but not quite, work as XHTML--and so have to be parsed as HTML anyway.

You're using undeclared entities in your pages, which isn't a problem when they're parsed as HTML, but is when they're parsed as X(HT)ML. But since no one will ever parse your pages as X(HT)ML it doesn't really matter. XHTML is a) hard to get right and b) mostly pointless. It's not an accomplishment to publish sort-of-XHTML pages that have to be parsed as HTML to actually work.


What my "undeclared entities" are was left undefined. Also, it's difficult to see how my code will "almost, but not quite, work as XHTML" and is just "sort-of-XHTML pages" when the Validator passes them as "XHTML 1.0 Strict" with no errors or warnings.

But here's my Firefox question: was he right about Firefox and "all browsers"? Does Firefox ignore my DOCTYPE and just go ahead a parse my pages as HTML 4 or 5?

Also, any comments you might have about my writing code to XHTML Strict standards would be most appreciated.

Thanks so much.

Ken
CentOS 6 Linux

DanRaisch
Moderator

User avatar
 
Posts: 124075
Joined: September 23rd, 2004, 8:57 pm
Location: Somewhere on the right coast

Post Posted January 5th, 2015, 1:51 pm

Moving to Web Development where those most likely to be able to answer this question are most likely to see it.

Frenzie

User avatar
 
Posts: 2135
Joined: May 5th, 2004, 10:40 am
Location: Belgium

Post Posted January 6th, 2015, 10:47 am

If you have undefined entities the W3C validator should point it out. Also, Opera/Presto and Firefox both failed on undefined entities last time I checked (2011-ish).

kenmorgan wrote:But here's my Firefox question: was he right about Firefox and "all browsers"? Does Firefox ignore my DOCTYPE and just go ahead a parse my pages as HTML 4 or 5?

XML error handling is in principle quite unfriendly to the user. I haven't checked the behavior recently, but I presume that person is talking about something like this. Alternatively they might be talking about XHTML5, which doesn't have a DTD and therefore doesn't define HTML entities like mdash. Presumably the idea is that you just type Unicode characters directly instead. However, that doesn't or shouldn't mean that XHTML5 is parsed as HTML 5.

I do not personally believe that XHTML has much to offer over HTML 4.01 Strict or HTML 5 for most use cases, but there's nothing necessarily wrong with it. It's only problematic when someone writes failing "XHTML" and never notices because e.g. IE never receives it with the right mimetype.

As I write this I realize the commenter might've also meant that you neglect to send an XHTML mimetype. If you don't then it does mean your page would be parsed as HTML, which in turn would mean that you're not using any of XHTML's unique features and it'd probably be more appropriate to switch to HTML 4.01 Strict or HTML 5.

I think that's about as much as anyone can say without actually seeing a page.
Intelligent alien life does exist, otherwise they would have contacted us.

kenmorgan

User avatar
 
Posts: 152
Joined: February 4th, 2010, 11:15 am

Post Posted January 9th, 2015, 9:56 am

Frenzie, thanks so much for the reply. Here are a few followup questions:

(1) In your second paragraph you mention "XHTML5." I haven't heard of that. If there is a standard newer than "XHTML 1.0 Strict," I would like to use it.

(2) You said,

I do not personally believe that XHTML has much to offer over HTML 4.01 Strict or HTML 5 for most use cases, but there's nothing necessarily wrong with it.


I'm sure you're correct in this assessment. However., the reason I wanted to write my code as "XHTML 1.0 Strict" is that a number of years ago, someone on another forum said something to the effect that "XHTML 1.0 Strict" was sort of a "cadillac" of standards for those who want to do truly a professional job of coding their Web sites. It does seem to be the most rigorous, does it not? That attracted me. Before retirement, I worked for a few years as a computer programmer (a mainframe, IBM System 370) and then later taught computer programming for many years at the college level. I always have preferred stricter languages (like Pascal) where, for example, you must declare variables before using them. (So although I use it in my Web pages, I consider JavaScript a sloppy language.) So with my attitude toward programming languages, should "XHTML 1.0 Strict" be the standard of choice for me?

(3) You also said,

As I write this I realize the commenter might've also meant that you neglect to send an XHTML mimetype. If you don't then it does mean your page would be parsed as HTML,


Ah...here's what I needed to know!!! NOWHERE did this "commenter" mention the "XHTML mimetype." This is exactly what I was NOT doing. My "mimetype" apparently comes from this meta statement I am using:

Code: Select all
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />


My code always passed the W3 Validator: "This document was successfully checked as XHTML 1.0 Strict!" So it seems the Validator checks my code for XHTML 1.0 Strict and ignores my HTML mimetype. But the browsers do not ignore it and proceed to parse my carefully written strict XHTML code as HTML! !@#$%^&* :) Is everything I said here correct?

(4) Finally, is this the correct meta statement I should be using:

Code: Select all
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />


Ken
CentOS 6 Linux

Frenzie

User avatar
 
Posts: 2135
Joined: May 5th, 2004, 10:40 am
Location: Belgium

Post Posted January 10th, 2015, 3:23 am

kenmorgan wrote:(1) In your second paragraph you mention "XHTML5." I haven't heard of that. If there is a standard newer than "XHTML 1.0 Strict," I would like to use it.

See https://blog.whatwg.org/xhtml5-in-a-nutshell

someone on another forum said something to the effect that "XHTML 1.0 Strict" was sort of a "cadillac" of standards for those who want to do truly a professional job of coding their Web sites. It does seem to be the most rigorous, does it not?

Because of its draconian error handling you'll know immediately if something's wrong. That's good if you're the one who sees it first, but not necessarily so great for the people you'd like to read your stuff.

But the browsers do not ignore it and proceed to parse my carefully written strict XHTML code as HTML! !@#$%^&* :) Is everything I said here correct?

(4) Finally, is this the correct meta statement I should be using:

Code: Select all
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />


Ken

Not exactly, but it's not a bad thing to have. :) That META statement is a fallback, which is (or might be) used when the HTTP Content-Type header is not available: i.e., when opening a file from disk instead of from a server. However, I believe in practice browsers treat the file extension as the only relevant indicator, with .htm and .html being treated as text/html and .xhtml being treated as application/xhtml+xml. Don't quote me on this though.

What you do need to do, if you want your XHTML to be treated as XHTML, is to send that mimetype in the HTTP headers. In Firefox you can see the headers through right click > View Page Info. On this page, for example, the relevant header reads "text/html; charset=UTF-8". If you search for something like XHTML mimetype combined with terms like Apache, PHP or whatever is relevant to you, I'm sure something decent must come up.
Intelligent alien life does exist, otherwise they would have contacted us.

kenmorgan

User avatar
 
Posts: 152
Joined: February 4th, 2010, 11:15 am

Post Posted January 12th, 2015, 6:25 pm

Thanks again, Frenzie. I needed to do some experimenting before getting back to you.

(1) You said,

That META statement is a fallback, which is (or might be) used when the HTTP Content-Type header is not available: i.e., when opening a file from disk instead of from a server. However, I believe in practice browsers treat the file extension as the only relevant indicator, with .htm and .html being treated as text/html and .xhtml being treated as application/xhtml+xml. Don't quote me on this though.


What my experiments indicated is that the meta statement from my previous email had no effect. I created two identical files, both with that SAME meta statement specifying "xhtml+xml." The only difference between the files was the file extension: one was .html and the other .xhtml. When I looked at the "Page Info" for each, the .html file had "Type: text/html," while the .xhtml file had "Type: application/xhtml+xml." I believe this is what you predicted. The "xhtml+xml." in the meta statement did not make Firefox parse the code as XHTML, but the file extension did.

I'm assuming that when the "page info" says "application/xhtml+xml" that means that Firefox IS INDEED parsing the code as XTHML??? Right?

(2) However, that Web site you referred me to for "XHTML5" made the following statement:

Polyglot document could serve as either HTML or XHTML, depending on browser support and MIME type.


It would seem that this author believes that the browser pays attention to the xhtml mime in a meta statement and parses accordingly. Firefox clearly does not. Could it be that other browsers do?

So it would now seem that all my original questions are answered: I can now get all my beautiful and correct "XHTML 1.0 Strict" code actually parsed as XHTML code.

(3) Am I right about this, though: it does seem that the W3 Validator, unlike Firefox, ignores BOTH the meta statement AND the file extension. My code has always been passing as "XHTML 1.0 Strict" with the old meta statement specifying "text/html" and with an .html file extension. It seems that the only thing the Validator pays any attention to when examining the code is the DOCTYPE. Would you agree?

(4) One last item. You said,

What you do need to do, if you want your XHTML to be treated as XHTML, is to send that mimetype in the HTTP headers.


I don't quite follow you here. What do you mean by "mimtype in the HTTP headers"? What are these headers? What is there syntax? Where are they placed in the code?

OR--are you simple referring to the file extension?

Thanks again.

Ken
CentOS 6 Linux

trolly
Moderator

User avatar
 
Posts: 39909
Joined: August 22nd, 2005, 7:25 am

Post Posted January 13th, 2015, 3:03 am

HTML headers are information sent from the server immediately before your page.
Here for example the headers for this page:

Proxy-Connection: close
Proxy-Authenticate: NEGOTIATE NTLM
Pragma: no-cache
Content-Type: text/html; charset=utf-8
Content-Length: 1558
Connection: close
Cache-Control: no-cache
Think for yourself. Otherwise you have to believe what other people tell you.
A society based on individualism is an oxymoron. || Freedom is at first the freedom to starve.
Constitution says: One man, one vote. Supreme court says: One dollar, one vote.

Frenzie

User avatar
 
Posts: 2135
Joined: May 5th, 2004, 10:40 am
Location: Belgium

Post Posted January 14th, 2015, 7:26 am

kenmorgan wrote:I'm assuming that when the "page info" says "application/xhtml+xml" that means that Firefox IS INDEED parsing the code as XTHML??? Right?

That's correct. When you subsequently introduce a syntax error, you should see the unpleasant result.

It would seem that this author believes that the browser pays attention to the xhtml mime in a meta statement and parses accordingly. Firefox clearly does not. Could it be that other browsers do?

The author is referring to the HTTP header, not the META element.

It seems that the only thing the Validator pays any attention to when examining the code is the DOCTYPE. Would you agree?

It wouldn't make much sense for it to do anything else, but I haven't examined it in-depth and certainly not recently.

I don't quite follow you here. What do you mean by "mimtype in the HTTP headers"? What are these headers? What is there syntax? Where are they placed in the code?

OR--are you simple referring to the file extension?

Thanks again.

Your server may be set up to send files with a .xhtml extension with the right mimetype automatically, but because of a lack of support in IE8 and lower I imagine it's unlikely. See e.g. http://protempore.net/~calvins/howto/xhtml-apache/

The only thing that matters for files served over HTTP is the mimetype sent along. Also see http://www.howtogeek.com/192628/mime-ty ... xtensions/
Intelligent alien life does exist, otherwise they would have contacted us.

kenmorgan

User avatar
 
Posts: 152
Joined: February 4th, 2010, 11:15 am

Post Posted January 14th, 2015, 9:47 am

That was very helpful, Frenzie. However, those two articles to which you referred me are a bit lengthy. I'll be studying them and may have a few questions when I'm done.

One thing for right now: you said,

Your server may be set up to send files with a .xhtml extension with the right mimetype automatically...


My server is a VPS, which gives me root access. So I should be able to set it up any way I want. Just need directions! :) There might be a way to make these settings using WHM (cPanel's GUI for root) or an SSH session in a terminal window. Maybe those articles you mentioned will explain what I need to do. Otherwise, to quote Arnold Schwarzenegger, "I'll be back!" :)

Ken
CentOS 6 Linux

Return to Web Development / Standards Evangelism


Who is online

Users browsing this forum: No registered users and 1 guest