...

View Full Version : What is the file ext. for an XHTML document?



Doctor_Varney
08-29-2010, 03:48 PM
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

VIPStephan
08-29-2010, 04:18 PM
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.

Doctor_Varney
08-29-2010, 06:50 PM
Thanks Stephan. The parts I understand I have highlighted. The rest... er... can I have in English please? :)


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 :thumbsup:

Dr. V

VIPStephan
08-29-2010, 07:24 PM
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.:


<html xmlns="http://www.w3.org/1999/xhtml">

This way you can, for example, “switch” from plain XML to XHTML in the current document:


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

Doctor_Varney
08-29-2010, 07:53 PM
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

effpeetee
08-29-2010, 08:57 PM
CSS can be put into the <head> section of the page.
<head>

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


</head>

Frank

VIPStephan
08-29-2010, 10:31 PM
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.


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

These questions are all answered in full detail in Wikipedia (http://en.wikipedia.org/) or by performing a web search.



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 (http://en.wikipedia.org/wiki/Standard_Generalized_Markup_Language#XML)) 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:


<?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.


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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum