Jump to content

HTML XHTML? Any difference?


cs.punk

Recommended Posts

  • Replies 151
  • Created
  • Last Reply

I personally beleive that HTML 4.0 strict with lower case tag names and trailing slashes in singular tags is the best method of programming in html [...]

 

You think deliberately putting syntax errors in your document is the "best method of programming"? That seems a bit odd to me.

 

i beleive that this should eb the standard not tthat it is correct to any of the current ones, to me the slash indicates a closing so any tag that doesnt require an opening tag should require to be its own self closing tag hence why i think it should have trailing slashes

Link to post
Share on other sites

The slash does not and has never meant a self-closing tag. I'll repeat myself: HTML is not XHTML (and vice versa).

 

i didnt say that all i said was that i was inputting my opinion and that having trailing slashs to me would make more sense, not that HTML or XHTML are the same as i know that they are not to be quite hinest i beleive that some of the things that have been changed / implemented into XHTML are stupid hence why i use HTML 4.0, i think someone in this thread has said it but im not sure, newest isnt always best and i beleive this to be true also.

Link to post
Share on other sites
  • 2 weeks later...

I just read this blog post. Not only ins Danial correct, it also shows how little a lot of web delevopers really know when putting some 'Valid XHTML 1.0' text on their sites. I'm very happy I took the (very small) effort to convert to strict, valid HTML 4.01. Should make it much easier for when HTML 5 reaches us.

Link to post
Share on other sites

Its funny cause every book and website tutorial you see suggest in their examples to use xhtml in the DTD. Plus as has already been stated before, most sites use it. It might not make it correct, but if everyone is doing it what difference does it make?

Also rss feeds use xml and some other APIs, so thats another use for it. Having looked at some xml code i dont fancy learning it just yet mind.

Link to post
Share on other sites

I'd just like to add to this topic that if you use xhtml 1.1 with the appriate header, you can't make use of an imagemap.

You got 2 choices, you write invalid code, or it does not work in firefox.

 

Most used browser by miles supporting xhtml actually served as xhtml so a bit hard to overlook.

Link to post
Share on other sites

I'd say it just boils down to the fact it isn't valid code, which every seems to care about (and quite rightly). It just simply isn't valid, never mind if browsers cope with your mistake (which is a blessing and a curse: end users don't notice but you're not coding properly).

 

The thing that actually got me is, XHTML has, for my needs, no advantages whatsoever, I was just swept up in the 'it's newer, let's use that' hype. And just because many sources use it for their DTDs, just means many sources are showing you invalid code (unless they're serving properly). Unfortuantly, you have to do your research on this one.

 

In addition, I'd say HTML 5 is going to bring features that, while XHTML will have as it's being developed in tandem (I think), it just won't be worth sticking with XHTML because you'll have to serve it correctly, which IE can't handle (XHTML 1.1 needs serving properly to validate, so you can guarantee the next version will!).

 

I'd rather validate my HTML 4.x now, so that it validates easily as 5 later.

Link to post
Share on other sites

Well upon hearing all this information and reading a lot about it I have to say I will be switching back to HTML strict and dropping this XHTML non-sense. I think the reason so many of us use it is because of that fact: Every body uses it! lol.

I agree though that the singlular tags feel like they should have the ending / to signify they are closed. It just seems natural. But will have to break that bad habbit.

Link to post
Share on other sites
  • 3 weeks later...

You guys are forgetting 3 main points regarding xHTML.

 

1) The w3 guys are coding geeks and will love to make everthing symmetrical

2) They love xml and eventually want to do away with html this is their stepping stone to achieving that

3) This will somehow keep them in a job generating income in one way or another. They will no dount reciieve funding for their work, either government or sponsorship money, there are always ulterior motives.

Link to post
Share on other sites

WOW! This thread had def opened my eyes. I always felt there was more to the html vs xhtml thing.... I will definitly be using html alot more than xhtml...

 

..does any one think that when HTML 5 is 'official' it will receive the hype that xHTML did?

Link to post
Share on other sites
  • 1 month later...

There really isn't any. It's personal choice. The idea behind XHTML was that it would be parsed using an XML mimetype (don't worry about what that is if you don't know), but IE doesn't support this, and since IE is the most used browser out there, it basically made XHTML pointless. Everyone just parses XHTML as HTML, and so they are eventually the same.

 

If you want to make a wise choice, parse using a strict version of either of them, and not the transitional version. Then make sure that your code is valid. This is much more important and will have more benefits for your code than the choice between HTML and XHTML.

 

Well said thanks!

Link to post
Share on other sites
  • 2 weeks later...
  • 1 month later...

this is a continuation of this discussion http://www.phpfreaks.com/forums/index.php/topic,266831.0.html

 

It is treated as html, but as I said, the xml is ignored, its not being parsed by the browser, as xml is ignored as it says here 'well-formedness errors may not be detected by user agents.', what its serving is html, so it cant be fake as the browser still sees it as html

 

php is ignored by a browser, and parsed by the php and 'spat out' as html, does that make php 'fake' html ?... no, it just means that browsers always parse as html and it needed a little help to parse it ( in the case of php ) .. does not mean its being read, its being ignored completely, so in the case of xml its doing the same thing, ignoring the xml, meaning what its serving to an end user is html, there is nothing 'fake' about it.

 

 

Link to post
Share on other sites

php is ignored by a browser, and parsed by the php and 'spat out' as html, does that make php 'fake' html ?... no, it just means that browsers always parse as html and it needed a little help to parse it ( in the case of php ) .. does not mean its being read, its being ignored completely, so in the case of xml its doing the same thing, ignoring the xml, meaning what its serving to an end user is html, there is nothing 'fake' about it.

 

Sorry, that's not how PHP works. Let's say we use Apache and PHP as a module. So, first you load the module. Then you add a line like this:

AddType application/x-httpd-php .php

in Apache's configuration file. What this line does is that it for any file with the extension .php, the MIME type should be application/x-httpd-php. However, the when you load the PHP module, Apache is being told all pages with the MIME type application/x-httpd-php should be sent by PHP first. When PHP is parsing a document it looks for things within <?php and ?> tags. Only data that is within these are PHP. Everything else is unknown and returned verbatim. So PHP parses things with the PHP tags (if there are any) and sets the Content-type to text/html (which can be changed by setting the default_mimetype directive or sending a header manually).

 

That is entirely not what is going on when you send a text/html document to a browser. What that says is that the entire document is HTML, so the entire document will be treated as HTML. That is unlike PHP where only the things within its delimiters are treated as HTML. Now, an HTML parser is required to be forgiving, so whenever it meets something that is invalid or unknown it is required to try to correct it, insofar possible.

 

But really, have you read this topic? If you have you'll know that the difference between HTML and XHTML is not just about syntax. The DOM will be different depending on which one you use.

 

I don't think you said this yet, but many people claim that XHTML is better because it's stricter. That may or may not be true, but either way it's paradoxical that these particular people exploit the fact that HTML is forgiving to make their strict "XHTML" work.

 

I'm not sure why you keep riding on that "fake" thing. Obviously you're not supposed to interpret it as fake in the literal sense. That's kind of why you use the little "" signs. The correct word is of course invalid.

Link to post
Share on other sites

You must know more about php than me as I am a beginner to php as anyone worth their weight would have done their research, I agree with what you said in this forum, the only thing I am having problems with is the serving of xhtml, xhtml is an extension of html, as browsers use html and not xhtml of course its going to be served as html, but my argument was what you stated in the other thread that its fake html or invalid html.

 

as its being ignored, yes its pointless to use it unless you are using xml in your html ( aside from the fact its easier to learn ), but it does leave the option to add it later if you want, to me, that means its more accessible, obviously not because its 'better' but because it gives the option if you want to use it..

 

as its parsed as html it cant be invalid once it has reached the end user even if you have used text/html, simply because the xml parts of it are being ignored.

 

if I had something like this

 

'this can be seen [ 'this is ignored because its xml' ] by a browser', it would not parse as that, it would only parse as 'this can be seen by a browser,' so what it is serving is what is expected text/html, as such it cant be invalid... that's the way I look at it anyway

Link to post
Share on other sites

No, it doesn't just come down to that.

 

Take this snippet for instance:

<table>
<tr>
	<td>1</td>
	<td>2</td>
</tr>
<tr>
	<td>3</td>
	<td>4</td>
</tr>
</table>

 

The DOM (Document Object Model) that is generated is not the same for the two content-types text/html (HTML) and application/xhtml+xml (XHTML).

 

Try to check out these two things:

http://daniel0.net/html_xhtml_test.php

http://daniel0.net/html_xhtml_test.php?xhtml=1

 

The first one is an HTML 4.01 Strict document served as text/html. The second one is an XHTML 1.0 Strict document served as application/xhtml+xml. Both of them validate on W3C's validator with no errors or warnings. The PHP source code is:

<?php
$html = !isset($_GET['xhtml']);

if (!$html) {
header('Content-type: application/xhtml+xml; charset=utf-8');
echo <<<EOF
<?xml version="1.0" encoding="utf-8"?>
<!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">

EOF;
}
else {
header('Content-type: text/html; charset=utf-8');
echo <<<EOF
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>

EOF;
}
?>
<head>
<?php if ($html): ?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php endif ?>
<title>Test (<?php echo $html ? 'HTML' : 'XHTML' ?>)</title>
</head>
<body>

<table>
<tr>
	<td>1</td>
	<td>2</td>
</tr>
<tr>
	<td>3</td>
	<td>4</td>
</tr>
</table>

</body>
</html>

 

As you see, the table is identical in both versions. Or is it? Well, no. In HTML, there is an optional <tbody> element, meaning it will be there whether you've put it in there or not. In XHTML there is no such thing as optional elements; either they are there or they are not.

 

There are loads of other subtle (and less subtle) differences between HTML and XHTML.

Link to post
Share on other sites

now thats what I call a lesson.. I am using a plug for firefox called 'page diff' amd you can see the difference in that, it must be using the dom to render as in the html one its

 

<table> 
    <tbody><tr> 
        <td>1</td> 
        <td>2</td> 
    </tr> 
    <tr> 
        <td>3</td> 
        <td>4</td> 
    </tr> 
</tbody></table>

 

and in the xml one its

 

<table> 
    <tr> 
        <td>1</td> 
        <td>2</td> 
    </tr> 
    <tr> 
        <td>3</td> 
        <td>4</td> 
    </tr> 
</table> 

 

I stand corrected and beg forgiveness lol

Link to post
Share on other sites

I will ask though... if you are building a site properly using div tags, what would it add or take away that would make it invalid ?...

 

if nothing, wouldn't that mean that its not invalid html so long as you have no tables at all?

Link to post
Share on other sites

The thing is that a document is only XHTML if its mime type is application/xhtml+xml, so that is what it takes to make it valid. However, Internet Explorer doesn't support that, so you'll have to do text/html instead, but if you do that it's no longer XHTML, but HTML with XHTML syntax, which is invalid. For instance <br /> is valid XHTML, but invalid HTML. It does work, but it is not correct/valid. It works because HTML is forgiving of errors.

 

You have a couple of options:

  • Use HTML syntax and MIME type text/html. This is valid.
  • Use XHTML syntax and MIME type application/xhtml+xml. This is also valid, but you'll cut off all Internet Explorer users.
  • Use XHTML syntax with MIME type text/html. This is invalid, but it does work (kind of). While a lot of people do it, it doesn't really make sense. First of all, your XHTML code will not be parsed as XHTML thus you will not be able to use any of the extra things XHTML offers (namespaces, etc.).

 

Therefore, I think that using HTML 4.01 Strict is the best option right now. There is nothing wrong with XHTML per se, but it's not a viable option because Internet Explorer has got a large browser market share, but doesn't support XHTML.

Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.