Forum Moderators: open

Message Too Old, No Replies

XHTML compliant or not?

The advantages of XHTML compliancy?

         

ffoeg

2:18 pm on Jan 12, 2006 (gmt 0)

10+ Year Member



Ok, i know that you make a new HTML document that is XHTML compliant, this bit of code is inserted at the beginning:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

what exactly does that code do? not only that, but what are the advantages of using XHTML as opposed to using normal HTML?

One of the irritating things that i have experienced with XHTML is that you can't centre anything vertically, although you can do it horizontally.

if you do not have any of that doctype definition in the beginning of the document, you have absolute freedom to arrange anything however you like (within limits of course).

Any help on this would be really appreciated!

Mistra

2:28 pm on Jan 12, 2006 (gmt 0)

10+ Year Member



Do it!

Check out my answer here :

[webmasterworld.com...]

Robin_reala

3:01 pm on Jan 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One thing to bear in mind is that you're not getting of the real benefits of XML unless you serve it as application/xhtml+xml MIME type, and IE refuses to load that.

But validating your site and using a doctype are still very important regardless of whether you use HTML or XHTML.

JAB Creations

3:07 pm on Jan 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you have time to learn and test things out like I do then I suggest going for it. Learning XHTML, it's associated mimetypes, and how to properly code JavaScript will keep you ahead of the game and most people in general.

Here are various levels of (X)HTML...
HTML 2.0
HTML 3.2
HTML 4.0
HTML 4.01 (Strict and Transitional)
XHTML 1.0 (Strict and Transitional)
XHTML 1.1 (no declaration, naturally strict)

I'm not sure how far back strict and transitional go but it stops with XHTML 1.1 which is only strict (it isn't declared). XHTML 2.0 basically does not exist yet.

I would suggest going with XHTML 1.0 transitional first unless you're really good with CSS to take out junk like align="center" and border="0". If you are then go with XHTML 1.0 strict...

Keep in mind that mimetypes have to be properly served.

[w3.org...]

You may serve XHTML 1.0 Strict as text/html so you won't have to worry about the mimetype now.

A lot of people will tell you that when you switch to XHTML 1.1 and serve it as application/xhtml+xml that you'll have a lot of changes to make. If you properly code your XHTML and CSS you should only have some very minor CSS adjustments like I did. JavaScript is a whole different matter. It seems like I'm having to relearn a lot but it's not a huge nightmare if you visit a place like this! ;)

So if you're new in general to HTML then stick with XHTML 1.0 Transitional. If you're looking to really separate content and style go with XHTML 1.0 strict. If you want to go all out then go with XHTML 1.1 served as application/xhtml+xml. Just be wary that if you serve application/xhtml+xml IE 7 will officially still not support this so you will have to improperly serve text/html to that and older browsers (use serverside scripting to do so such as ASP or PHP). Plus more importantly if your site is live or has traffic besides yourself and you have JavaScript on there you will definitely test your code locally before sending anything online. I think unless you have hordes of time on your hands don't go beyond XHTML 1.0 Strict until you have the time and dedication to learn clientside at it's greatest current depth.

encyclo

6:06 pm on Jan 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The key is standards compliancy, not XHTML compliancy. Standards compliancy matters as you are adhering to a generally well-documented specification, it matters because it helps ensure consistency cross-browser, and it matters because when you do come across a problem the fact that the page validates instantly excludes a whole gamut of possible causes. Markup is often difficult enough to debug as it is, but when you're dealing with "tag soup" it can become impossible.

XHTML matters much less: the biggest difference is between strict and transitional. The strict versions of both HTML 4.01 and XHTML 1.0 leave out many presentational elements which are replaced by CSS. Using a strict doctype will push you into keeping the style of the page separate from the structure.

A word about mime types: I must disagree with some of the comments above.

The mime type debate is the dark side of XHTML. In theory you should be serving XHTML with the mime type

application/xhtml+xml
instead of the usual
text/html
which is associated with HTML. In practice, you should never do so. IEs total lack of support is already a massive barrier, but even if IE supported
application/xhtml+xml
it should still be avoided in any situation other than for a test page. It is important to ask a supplementary question which is outside of the standards debate. Will what I'm doing help the end user? In the case of XHTML served as
application/xhtml+xml
the answer is definitely no. Forcing XHTML into the strait-jacket of XMLdraconian error-handling can be disastrous for business as well as for end users. One error, and your site will just give an XML error message. This approach is simply crazy when with
text/html
the page will display despite the error. If it is your site, why risk the site going down for a markup error? If you design for others, how will they react when your site breaks so easily?

One thing to bear in mind is that you're not getting of the real benefits of XML unless you serve it as application/xhtml+xml MIME type

There is no advantage to XHTML served as

application/xhtml+xml
, but there are multiple, critical disadvantages.
application/xhtml+xml
is a technological dead-end which will never see the light of day outside a few hardcore geeks using it in tightly-controlled conditions. Try it out if you want (but not on anything important), but don't get sidetracked into thinking it's the future.

Back to your original question: personally I usually stick to HTML 4.01, but if you prefer the simpler XHTML syntax (and ignore the mime type issue) then by all means go ahead and use XHTML 1.0. And it is possible to center vertically in standards-compliance mode (triggered by the presence of an appropriate doctype) - you can use CSS to fix the

html
and
body
heights to 100%. :)

ffoeg

6:29 pm on Jan 12, 2006 (gmt 0)

10+ Year Member



so are there any notable differences between HTML and XML/XHTML?

sorry for the ignorance, i am still quite new to html.

encyclo

6:36 pm on Jan 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



so are there any notable differences between HTML and XML/XHTML?

There are several differences in syntax that you need to know about. The first is that XHTML is lower-case only, whereas HTML is case-insensitive. The second is that XHTML requires all elements to be closed: for example in HTML you can omit the closing

</p>
of a paragraph whereas this is not permitted in XHTML. Elements without a closing tag must be closed with a trailing slash:

<img src="image.jpg" alt="text" [b]/[/b]>

Also all attributes must be quoted, unlike in HTML where you could have

border=0
and such.

XHTML syntax is easier to learn as there are fewer exceptions. However it will be treated as HTML by the browser so the end result between using XHTML 1.0 or HTML 4.01 is the same.

pageoneresults

6:45 pm on Jan 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



So are there any notable differences between HTML and XML/XHTML?

<img src=""image.jpg alt="text" />

Those closing tags can become an issue if you are not careful. Many of us are used to working in an HTML environment where our programs are set up to code accordingly (they may not use XHTML closing tags). Sometimes though you find yourself cutting and pasting from various resources you have and you end up with HTML and XHTML mixed together. If you are not validating your pages after every change, these can creep on you and get out of hand.

I've noticed a few pages on the W3 that don't validate and most of the errors have to do with XHTML closing tags. ;)

I've been sticking with HTML 4.01 Strict as the only basic difference I can see with the coding I work with is the DTD and the closing tags. I can easily convert the pages to XHTML 1.0 Strict if need be through a Find and Replace routine.