Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-29-2010, 02:48 PM   PM User | #1
Doctor_Varney
Regular Coder

 
Doctor_Varney's Avatar
 
Join Date: Mar 2008
Location: Midlands, UK
Posts: 649
Thanks: 45
Thanked 29 Times in 28 Posts
Doctor_Varney will become famous soon enough
What is the file ext. for an XHTML document?

I know that .html is what you put after the name of an HTML file but what file extension do I use to save it as an XHTML document? Is it .xml or .xhtml? Apart from having to close all <tags /> properly, what else do I need to know about writing it?

Thanks

Dr. V
__________________
Definition: Computer rage is a heightened physiological response with associated feelings of anger and frustration[1] resulting from using a computer or other complex electronic device. It may result in the physical assault of the computer or similar item.[2] Computer use often leads to verbal abuse and occasionally physical violence towards the object.[3] Computer rage may be caused by distress due to a hardware or software problem which the enraged person is unable to correct.
Doctor_Varney is offline   Reply With Quote
Old 08-29-2010, 03:18 PM   PM User | #2
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,592
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
As far as I know XHTML documents have the extension .xhtml. Of course you can also use .xml as extension since (true) XHTML is a subset of XML and with an XML prologue and the XML namespace attribute you define it to be XHTML.

All XHTML must be written lowercase (that counts for tags and attributes) and must be well formed (i. e. matching opening and closing tag pairs). All text that is not supposed to be interpreted by the XML parser (e. g. interal JavaScript) must be written as “character data” (CDATA), i. e. between <![CDATA[ and ]]> tags.
__________________
Don’t click this link!

Last edited by VIPStephan; 08-29-2010 at 03:21 PM..
VIPStephan is offline   Reply With Quote
Old 08-29-2010, 05:50 PM   PM User | #3
Doctor_Varney
Regular Coder

 
Doctor_Varney's Avatar
 
Join Date: Mar 2008
Location: Midlands, UK
Posts: 649
Thanks: 45
Thanked 29 Times in 28 Posts
Doctor_Varney will become famous soon enough
Thanks Stephan. The parts I understand I have highlighted. The rest... er... can I have in English please?

Quote:
Originally Posted by VIPStephan View Post
As far as I know XHTML documents have the extension .xhtml. Of course you can also use .xml as extension since (true) XHTML is a subset of XML and with an XML prologue and the XML namespace attribute you define it to be XHTML.

All XHTML must be written lowercase (that counts for tags and attributes) and must be well formed (i. e. matching opening and closing tag pairs). All text that is not supposed to be interpreted by the XML parser (e. g. interal JavaScript) must be written as “character data” (CDATA), i. e. between <![CDATA[[/ICODE] and [ICODE]]]> tags.
Cheers

Dr. V
__________________
Definition: Computer rage is a heightened physiological response with associated feelings of anger and frustration[1] resulting from using a computer or other complex electronic device. It may result in the physical assault of the computer or similar item.[2] Computer use often leads to verbal abuse and occasionally physical violence towards the object.[3] Computer rage may be caused by distress due to a hardware or software problem which the enraged person is unable to correct.
Doctor_Varney is offline   Reply With Quote
Old 08-29-2010, 06:24 PM   PM User | #4
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,592
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
XHTML is a part of XML. In XML you can typically define your own elements and attributes but XHTML is kind of a “predefined” part of XML (such as MathML or SVG) where you have to use the elements that are defined by the W3C (and programs may have predefined layout or function for these elements). In order to use XHTML as such you have to tell the parser (e. g. the web browser) so it knows that it’s XHTML and is parsing it as such. This is done by defining a name space in your XML code, e. g.:

Code:
<html xmlns="http://www.w3.org/1999/xhtml">
This way you can, for example, “switch” from plain XML to XHTML in the current document:
Code:
<customelement customattribute="value">custom text</customelement>
<html xmlns="http://www.w3.org/1999/xhtml">
	…
	<h1 class="whatever">this is XHTML code</h1>
</html>
Same goes for SVG where you use the SVG namespace to tell the browser that you’re gonna use a vector graphic in the current XML document.

As for the CDATA stuff do a search and you will be helped. Basically in XHTML, if you’re writing JS in the document you have to declare it as (unparsed) character data so the parser doesn’t interpret characters like “&” and “<” as X(HT)ML.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 08-29-2010, 06:53 PM   PM User | #5
Doctor_Varney
Regular Coder

 
Doctor_Varney's Avatar
 
Join Date: Mar 2008
Location: Midlands, UK
Posts: 649
Thanks: 45
Thanked 29 Times in 28 Posts
Doctor_Varney will become famous soon enough
Okay... some of that makes sense. Thank you. I didn't know what 'parser' meant. So 'parser' is just another word for 'web browser' then?

What does SVG stand for and what is a "namespace" please?

Okay - down to dumb basics here... I write HTML and all my tags are closed properly, etc and everything is in lower case (as I have always done). My CSS is always in a seperate style sheet because I actually don't know how to do it any other way or where else it should go. What actually happens when I save my file, not as .html, but as .xhtml?

Does saving it as .xhtml mean that the different browsers will all read my CSS the same as each other?

Can older browsers read XHTML?

Dr. V
__________________
Definition: Computer rage is a heightened physiological response with associated feelings of anger and frustration[1] resulting from using a computer or other complex electronic device. It may result in the physical assault of the computer or similar item.[2] Computer use often leads to verbal abuse and occasionally physical violence towards the object.[3] Computer rage may be caused by distress due to a hardware or software problem which the enraged person is unable to correct.

Last edited by Doctor_Varney; 08-29-2010 at 07:21 PM..
Doctor_Varney is offline   Reply With Quote
Old 08-29-2010, 07:57 PM   PM User | #6
effpeetee
Senior Coder

 
effpeetee's Avatar
 
Join Date: Feb 2007
Location: Clapham Junction - London SW
Posts: 4,884
Thanks: 228
Thanked 204 Times in 203 Posts
effpeetee is an unknown quantity at this point
CSS can be put into the <head> section of the page.
<head>

<style type="text/css">
CSS here.
</style>


</head>

Frank
__________________
* Sources (updated: 21.11.2012.
Using Windows 8 Professional. 64bit with HP Photosmart 5510 printer Very useful site here.
effpeetee is offline   Reply With Quote
Old 08-29-2010, 09:31 PM   PM User | #7
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,592
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
Quote:
Originally Posted by Doctor_Varney View Post
I didn't know what 'parser' meant. So 'parser' is just another word for 'web browser' then?
Not quite. A parser, from what I understand, can be any program that can read and interpret the code you feed it. For example, documents created with OpenOffice or Microsoft Office are all basically written in XML, and both of these programs are parsing the XML to make the text documents out of the files you eventually see on your screen.

Quote:
Originally Posted by Doctor_Varney View Post
What does SVG stand for and what is a "namespace" please?
These questions are all answered in full detail in Wikipedia or by performing a web search.

Quote:
Originally Posted by Doctor_Varney View Post
Okay - down to dumb basics here... I write HTML and all my tags are closed properly, etc and everything is in lower case (as I have always done). My CSS is always in a seperate style sheet because I actually don't know how to do it any other way or where else it should go. What actually happens when I save my file, not as .html, but as .xhtml?
Well how XHTML syntax is interpreted depends on how the server is set to handle it (especially with regards to the file ending). For example some servers are set to treat files with the ending .php as PHP 4 and some treat it as PHP 5 by default (which makes a difference in some cases). Likewise some servers handle HTML files with the extension .htm and .html as classic HTML (which is based on SGML) while they treat files with the extension .xht and .xhtml as XHTML (which is based on XML). However, how certain file types are treated can be set in the server’s httpd.conf file I suppose, and/or in an htaccess file.

Additionally servers usually handle XHTML as XHTML if the MIME type is set to “application/xml+xhtml” (i. e. <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />). However, since IE doesn’t support XML (it won’t parse the data but rather ask to download the file) most of the time we really serve XHTML as tag soup (i. e. HTMLish code based on SGML with all its error handling customs) rather than true clean XML by using the text/html MIME type.

Now, that said: I’m not entirely certain about this as I’ve only had a glimpse on that yet but from what I know if you load your stylesheets in the head of the XHTML file (like we’re used to) then it should parse this alright. However, as we’re having an XML file we could as well load the CSS using the appropriate XML way:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="stylesheet.css"?>
<html xmlns="http://www.w3.org/1999/xhtml">
…
This way you can style other XML code, too, not just the XHTML.

Quote:
Originally Posted by Doctor_Varney View Post
Does saving it as .xhtml mean that the different browsers will all read my CSS the same as each other?

Can older browsers read XHTML?
1) No. How browsers display stuff depends on their support of stuff. If the programmers of IE don’t implement the support of certain CSS properties, IE won’t support it, regardless of the file type you feed it. And as a matter of fact – as I mentioned earlier already –, IE doesn’t support the entire XML at all which is why it actually doesn’t matter if you write HTML or XHTML as both are usually served with the MIME type “text/html”.

2) As I said in point one: It depends if the developers implemented support of XML in the first place. The older the browser versions are the less likely is the support of “true” XHTML. And IE doesn’t support it up until today.

So, I’m not sure if all I said is 100% correct (anyone feel free to correct me) but anyway: Many questions you have can be researched on the internet, and Wikipedia is a good first source.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:10 AM.


Advertisement
Log in to turn off these ads.