Jump to content

HTML XHTML? Any difference?


cs.punk

Recommended Posts

I personally use it because I don't just code websites. HTML is purely for websites, whereas XML (which xhtml is based on) is used for all sorts of stuff.

 

For example, I made a firefox extension in XML the other day.

 

Also, I just prefer the syntax. Like, it makes sense to self close a tag if it doesn't have an end tag....

 

It is just personal preference though.

Link to comment
Share on other sites

  • Replies 151
  • Created
  • Last Reply

Top Posters In This Topic

I don't understand one thing though. If XHTML has no added benefits over HTML and if IE doesn't support it, why are people still using it?

 

cuz... Microsoft wants to govern everything...

and this is not the only thing they want their own way

 

take a look at CSS -> IE does not respect the standards

UTF-8 -> Microsoft uses it's own version of Unicode

JS -> IE does not respect the standards

SVG image format (which is great) -> not supported in IE

PNG transparency -> was only recently corrected in IE

etc. etc.

 

in order to make things change at Microsoft's end, we, developers, have to make use of these advanced techniques...

We have to, and we can, force them to comply to the standards...

Link to comment
Share on other sites

If XHTML has no added benefits over HTML and if IE doesn't support it, why are people still using it?

 

Because people think XHTML is cooler and because they do not know what they're doing.

 

Well that's not true is it? I've just pointed out several reasons why I personally use it. I'm sure other people have their own reasons as well...

Link to comment
Share on other sites

That something works doesn't mean it's used the correct way.

 

People might be able to understand me if I use incorrect grammar when speaking or writing, and as such you could say that it "works". However, just because people understood what I said doesn't make my grammar correct.

 

"Works" and "is correct" are two entirely different concepts.

Link to comment
Share on other sites

No, you're forgetting something. HTML is forgiving, XHTML (XML) is not. You ARE using HTML because you serve it as text/html. The DTD is not what determines whether a document is XHTML or HTML. It's the mime type. The DTD is merely a set of grammar constraints. Without a DTD, an XML document cannot be said to be valid, but only well-formed. Well-formed-ness is determined the syntax ("are all elements closed?", "are the elements nested properly?" etc.). Validity is determined by DTD. The DTD specifies which elements that are allowed, which elements that are allowed within other elements, which attributes an element may have and possibly what values an attribute may have.

 

Now, seeing as you serve your document as text/html this means it will be parsed according to the rules of HTML, and HTML is not XML despite the fact that it looks fairly similar to it. Because HTML is forgiving it means that it can work without being correct. You are not using XHTML. You are per definition only using XHTML if your document has the mime-type application/xhtml+xml. Saying that your document is XHTML otherwise is pure rubbish.

Link to comment
Share on other sites

Yeah, but that's the point; I can send my page as xhtml. And I actually would if it wasn't for internet explorer.

 

It's coded in complete valid xhtml; I've tested it. If IE suddenly started supporting it, I would actually send my page as xhtml. But it doesn't. So as you say, I'd be cutting off a large portion of my "market" if I did so.

 

So I can use xhtml in the right way, I just don't because of flaws in something I have no control over- IE.

 

And hey! I just noticed your site-

 

1. It's written in xhtml

2. It's transitional

3. It's served as text/html

 

So in effect you're stating that you don't know how to code yourself?

Link to comment
Share on other sites

Yes you can, but you are currently not doing it. You are not using XHTML, but invalid HTML. It will never be XHTML unless you give it the correct mime-type. All UAs are rendering your documents as HTML, a subset of SGML and thus according to its rules.

 

I know this forum is wrongly served as XHTML 1.0 Transitional with text/html, but that's SMF's fault and you'll have to get them to change it. I also know that the main site here is served as XHTML 1.0 Strict with text/html, but that will be fixed in the next release and changed to HTML 4.01 Strict.

 

It's also not just a matter of syntax. There are differences in both DOM and CSS depending on whether the document is XHTML or HTML. Some tags are implicit in HTML, for instance the <tbody> tag. If you omit a <tbody> tag in a <table> then it will still exist DOM. That's not the case in XHTML. It will not be there. HTML is also case-insensitive whereas XHTML isn't. This goes in DOM as well. In XHTML someDocument.onClick is valid in HTML, but invalid in XHTML. You'll also find that document.write() doesn't work in XHTML for instance.

 

You also said yourself that while temporarily having switched to the correct mime type that your Javascript broke. This further emphasizes the fact that it's not just a matter of changing the mime type when switching between XHTML and HTML. There are other, not always obvious, things that need to be taken into consideration, and in some instances those subtle differences may break things.

 

Another reason why one might choose HTML over XHTML could be size considerations. HTML can be smaller because it for some attribute values do not require quotes, some end tags are not required and you will not be using the self closing tag. For a single request this difference is of course negligible, but if it's intended for an environment with extremely limited bandwidth or you are receiving a massive volume of hits then it can make a difference. Take for instance Google. On all their pages they get several billions of hits each months and using HTML can make a notable difference considering it was estimated in 2006 that YouTube alone spent 1 million dollars each month on bandwidth source. Three years have passed since and the bandwidth will undoubtedly have increased.

Link to comment
Share on other sites

I think what Daniel is getting is that you don't use XHTML when you could just as easily use HTML to get the job done and over with.

 

It's about the same concept as rich spoiled kids buying the most expensive item to do something rather than just getting a generic one. For instance, say you wanted to rake your yard..simple enough....rake it! On the other hand, a person could also simply shell out a couple hundred dollars at Lowe's and buy an air compressor, attach a hose to it and REALLY clean the yard.

 

So now everytime you want to rake the yard you pull out the air compressor. For the sake of argument let's say you have no carpentry skills and no other reason to own an air compressor. So now you're the only jackass using a $500 air compressor to rake his yard while Joe the carpenter down the road is stuck using simple tools like a nail and hammer, when he could easily borrow your air compressor and rent a nail gun. Leaving you with your air compressor having no other use than to lend out to people.

 

I may have went a little overboard on the analogy. But in conclusion...if you're using XHTML and you have no reason whatsoever to even need XHTML...then the answer is, you don't need it. It only makes your site more "expensive" and you'll have to code around the people who can't view the page just because you think it is cool to use the newest technology.

Link to comment
Share on other sites

Daniel to take this conversation farther in a constructive manor can you educate me on DOM?

 

DOM means Document Object Model. It's a hierarchical tree composed of all the elements of an (X)HTML document (plus a lot of other stuff). Each of the objects in the the DOM tree are called nodes. Each node has a series of attributes. When you are accessing an HTML element using Javascript then it's DOM you're using.

 

Here are some links for you:

http://www.w3.org/DOM/DOMTR

http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/

http://www.w3.org/TR/DOM-Level-2-Core/

http://www.w3.org/TR/DOM-Level-3-Core/

Link to comment
Share on other sites

It's all about the conformity and syntax standardization and validation.

 

HTML has a very loose syntax, and that makes it very hard for browsers to display the same things the same way, because each may have their own way of interpreting it.

 

XHTML is meant to be more rigid in that regard, and easier to read by browsers, with only ONE WAY of writing tags and attributes, and a very clear definition of what each tag may contain and not contain, and in what order it should be.

 

For example, each tag has to have a closing tag in XHTML, while in HTML, you "could" omit one and even tough your systax was incorrect, some browsers would still display it correctly. Also, all tags attributes in XHTML must be in lowercase, and attribute values must be enclosed in quotes or double-quotes. In HTML, you could write tags and attributes in uppercase, and obmit quotes if you wanted. You could also write special attributes such as "disabled" alone, without any key in front. (i.e. <input type=text disabled> instead of <input type="text" disabled="disabled" />).

Link to comment
Share on other sites

That's nonsense. The HTML parsing rules are perfectly clear.

 

For example, each tag has to have a closing tag in XHTML, while in HTML, you "could" omit one [...]

 

That's not more difficult to parse. Not all elements allow omission of the end tag. A tag like <p> is an example of a tag where that's optional. The DTD clearly specifies which tags that are allowed to be within a paragraph tag, so if it meets a tag that's not allowed inside <p> then it'll just implicitly close it and start the other one. It's perfectly simple.

 

Also, all tags attributes in XHTML must be in lowercase [...]

 

Again, no problem. Algorithmically it's not really difficult to do a case-insensitive match.

 

[...] and attribute values must be enclosed in quotes or double-quotes.

 

Still not a problem. It's very precisely defined which characters you are allowed to use if you omit the quotes. You are allowed to use characters the letters a-z and A-Z, digits 0-9, hyphens, periods, underscores and colons. It's not difficult to parse that at all.

 

You could also write special attributes such as "disabled" alone, without any key in front. (i.e. <input type=text disabled> instead of <input type="text" disabled="disabled" />).

 

So what? How is that a problem? The specs allow for empty attribute values and it's not at all difficult to parse that.

 

 

Maybe you should have a read over the specs before making claims like that. In fact, in my opinion the HTML 4.01, XHTML 1.0 and CSS 2.1 specifications are required reading for anyone who is serious about web development.

 

As a matter of fact (and this is probably fourth time I've said it now), your so-called "rigid" XHTML is parsed according to the so-called "loose" and "ambiguous" rules of HTML seeing as you're unlikely to block off all the IE users by serving it as application/xhtml+xml.

Link to comment
Share on other sites

Ok...well, this conversation is like...a banana farmer trying to convince an orange farmer bananas are better. The banana prefers bananas because...that's what he's used to. The same applies to the orange farmer.

 

But as I've stated in other threads similiar to this one, I don't just code websites. I'm interested in coding all sorts of stuff, for example, I made a Firefox extension last week. I made it in xml.

 

Which is another reason I use xhtml. html is just for web pages; there's not really much else you can use it for, whereas xml/xhtml is used for heaps of stuff. So, why not learn/use the one that you learn/use the most..?

 

And in regard to what I said about your site, I actually meant your personal site, as in what comes up when I click on that little globe thingy next to your username.

 

So in effect you're stating that you don't know how to code yourself?

Ouch you are asking for a world of trouble.

 

And, I'm not "asking for trouble", I'm simply enquiring why someone who seems to despise xhtml so much has their own site written in it.

Link to comment
Share on other sites

If you take a closer look you'll notice it's running WordPress. Another open source script. Ask its authors, why it uses XHTML.

 

[edit]

 

Oh... and I wouldn't say Daniel despises XHTML. He's just explaining, that having XHTML served as HTML is actually pointless...

Link to comment
Share on other sites

Which is another reason I use xhtml. html is just for web pages; there's not really much else you can use it for, whereas xml/xhtml is used for heaps of stuff. So, why not learn/use the one that you learn/use the most..?

 

Why not learn both? Computer science is a gigantic toolbox. The more you know (the more tools that are in your toolbox) the more things you can do and the more your skills will be worth. Part of what makes you a good developer is knowing when to use what tool over another. In this instance XHTML really is the inferior choice, at least until Microsoft decides to give IE XHTML support and/or IE's market share becomes too insignificant to bother with. I'm afraid there is no catch-all good-for-everything technology you can just use. Otherwise we might as well just use binary punch cards for everything related to computing.

 

And in regard to what I said about your site, I actually meant your personal site, as in what comes up when I click on that little globe thingy next to your username.

 

Sorry, I didn't actually notice your remark about my website. I just added the "on PHP Freaks we use" thing as a disclaimer before anyone mentioned it. Anyway, the HTML markup is the default Wordpress theme. I've been thinking about creating a custom one for a while, but I've always postponed it for more important stuff such as paid freelance web development and consulting.

Link to comment
Share on other sites

Oh... and I wouldn't say Daniel despises XHTML. He's just explaining, that having XHTML served as HTML is actually pointless...

 

Indeed, I don't despise XHTML. I just don't think that it currently is a viable option for web development unless you have very particular needs such as having to use e.g. MathML.

 

I also do not see how you can discard all the facts presented in this thread and just say "but I prefer XHTML".

Link to comment
Share on other sites

Oh right, I just assumed you made your blog yourself, my apologies.

 

I also do not see how you can discard all the facts presented in this thread and just say "but I prefer XHTML".

I'm not disregarding any facts at all, I'm simply stating why I prefer it. However, I understand why you prefer html, but tbh, I don't think it's really worth learning both, since they're so similiar. I've already programmed my entire site with xhtml. Even if I wanted to, I can't really be bothered to change it.

 

When I was re-writing my site, I decided to flick through W3Schools.com to pick up some tips and stuff, and I stumbled upon xhtml. They appeared to suggest that xhtml was far superior to html, and the fact that w3.org is written in it was encouragement enough.

Link to comment
Share on other sites

Indeed... w3.org is not giving a good example with this :)

 

Lol wtf, they like, invented web standards...

Maybe they use it because it's neater, or possible for any of the other reasons I stated.

Or maybe they just think it's "cooler" ;)

Link to comment
Share on other sites

Sorry to break it for you, but W3Schools isn't affiliated with W3C. W3Schools is created by an independent consultancy firm called Refsnes Data based in Norway. I guess they're called W3Schools because they try to teach you the technologies set forth by W3C.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • 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.