XHTML: Difference between revisions

The educational technology and digital learning wiki
Jump to navigation Jump to search
Line 16: Line 16:
# The root element of the document must contain an xmlns declaration for the XHTML namespace. Examples:
# The root element of the document must contain an xmlns declaration for the XHTML namespace. Examples:
   <html xmlns=  "http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
   <html xmlns=  "http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <h:html xmlns:h="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  &lt;h:html xmlns:h="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
# There must be a DOCTYPE declaration in the document prior to the root element.  
# There must be a DOCTYPE declaration in the document prior to the root element.  
# The DTD subset must not be used to override any parameter entities in the DTD.
# The DTD subset must not be used to override any parameter entities in the DTD.
Line 38: Line 38:
=== Example ===
=== Example ===


  <?xml version="1.0" encoding="UTF-8"?>
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  <!DOCTYPE html  
  &lt;!DOCTYPE html  
     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
   <head>
   &lt;head&gt;
     <title>Virtual Library</title>
     &lt;title&gt;Virtual Library&lt;/title&gt;
   </head>
   &lt;/head&gt;
   <body>
   &lt;body&gt;
     <p>Moved to <a href="http://example.org/">example.org</a>.</p>
     &lt;p&gt;Moved to &lt;a href="http://example.org/"&gt;example.org&lt;/a&gt;.&lt;/p&gt;
   </body>
   &lt;/body&gt;
  </html>
  &lt;/html&gt;


== Composite documents ==
== Composite documents ==
Line 57: Line 57:
; MathML example
; MathML example


  <?xml version="1.0" encoding="iso-8859-1"?>
  &lt;?xml version="1.0" encoding="iso-8859-1"?&gt;
  <xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml">
  &lt;xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml"&gt;
   <xhtml:body>
   &lt;xhtml:body&gt;
     <xhtml:h1>A Compound Document</xhtml:h1>
     &lt;xhtml:h1&gt;A Compound Document&lt;/xhtml:h1&gt;
     <xhtml:p>A simple formula using MathML in XHTML.</xhtml:p>
     &lt;xhtml:p&gt;A simple formula using MathML in XHTML.&lt;/xhtml:p&gt;
     <mathml:math xmlns:mathml="http://www.w3.org/1998/Math/MathML">
     &lt;mathml:math xmlns:mathml="http://www.w3.org/1998/Math/MathML"&gt;
       <mathml:mrow>
       &lt;mathml:mrow&gt;
         <mathml:msqrt>
         &lt;mathml:msqrt&gt;
           <mathml:mn>49</mathml:mn>
           &lt;mathml:mn&gt;49&lt;/mathml:mn&gt;
         </mathml:msqrt>
         &lt;/mathml:msqrt&gt;
         <mathml:mo>=</mathml:mo>
         &lt;mathml:mo&gt;=&lt;/mathml:mo&gt;
         <mathml:mn>7</mathml:mn>
         &lt;mathml:mn&gt;7&lt;/mathml:mn&gt;
       </mathml:mrow>
       &lt;/mathml:mrow&gt;
     </mathml:math>
     &lt;/mathml:math&gt;
   </xhtml:body>
   &lt;/xhtml:body&gt;
  </xhtml:html>
  &lt;/xhtml:html&gt;




* It is also possible to include XHTML tags in any XML document markup. E.g. here is an example:
* It is also possible to include XHTML tags in any XML document markup. E.g. here is an example:


  <?xml version="1.0" ?>
  &lt;?xml version="1.0" ?&gt;
  <?xml-stylesheet href="xml_plus_xhtml.css" type="text/css"?>
  &lt;?xml-stylesheet href="xml_plus_xhtml.css" type="text/css"?&gt;
  <page xmlns:html="http://www.w3.org/1999/xhtml" updated="jan 2007">
  &lt;page xmlns:html="http://www.w3.org/1999/xhtml" updated="jan 2007"&gt;
  <title>Hello friend</title>
  &lt;title&gt;Hello friend&lt;/title&gt;
  <list>
  &lt;list&gt;
   <!-- we use an HTML tag below to include a picture -->
   &lt;!-- we use an HTML tag below to include a picture --&gt;
   <html:img src="photo.jpg"/>
   &lt;html:img src="photo.jpg"/&gt;
   <item price="10"> White plate </item>
   &lt;item price="10"&gt; White plate &lt;/item&gt;
   <item price="20"> Gold plate </item>
   &lt;item price="20"&gt; Gold plate &lt;/item&gt;
   <item price="15"> Silver plate </item>
   &lt;item price="15"&gt; Silver plate &lt;/item&gt;
  </list>
  &lt;/list&gt;
  <comment> Written by <html:a href="http://tecfa.unige.ch/tecfa-people/schneider.html">DKS/Tecfa</html:a> , feb 2007 </comment>
  &lt;comment&gt; Written by &lt;html:a href="http://tecfa.unige.ch/tecfa-people/schneider.html"&gt;DKS/Tecfa&lt;/html:a&gt; , feb 2007 &lt;/comment&gt;
  </page>
  &lt;/page&gt;


== Current issues ==
== Current issues ==


* XHTML is badly supported by IE6 and IE7. I.e. current (15:01, 12 March 2007 (MET)) Microsoft browser do not recognize the application/xhtml+xml mimetype, which makes it difficult to include XSLT stylesheets or other languages such as SVG or MathML.
* XHTML is badly supported by IE6 and IE7. I.e. current (15:02, 12 March 2007 (MET)) Microsoft browser do not recognize the application/xhtml+xml mimetype, which makes it difficult to include XSLT stylesheets or other languages such as SVG or MathML.


There are workarounds to somewhat deal with IE 6/7:
There are workarounds to somewhat deal with IE 6/7:
Line 103: Line 103:
=== Standards ===
=== Standards ===


* [http://www.w3.org/TR/html/ HTML, Latest Version] (XHTML 1.0 as of 15:01, 12 March 2007 (MET)]
* [http://www.w3.org/TR/html/ HTML, Latest Version] (XHTML 1.0 as of 15:02, 12 March 2007 (MET)]
* [http://www.w3.org/TR/xhtml1/ XHTML 1.0]
* [http://www.w3.org/TR/xhtml1/ XHTML 1.0]
* [http://www.w3.org/TR/xhtml-basic/ XHTML Basic 1.1] (still a working draft as of March 2007).
* [http://www.w3.org/TR/xhtml-basic/ XHTML Basic 1.1] (still a working draft as of March 2007).

Revision as of 16:02, 12 March 2007

Draft

Definition

  • XHTML is a family of current and future Web document types and modules that reproduce, subset, and extend HTML4.01. XHTML family document types are XML conformant, and designed to work in conjunction with XML-based editors and user agents.


XHTML documents

Valid XHTML documents

  • XHTML documents must be wellformed and valid according to the XML specification, except that an XML declaration is not mandatory (only encouraged).

In addition:

  1. It must conform to the constraints expressed in one of the three variants (defined by DTDs)
  2. The root element of the document must be html
  3. The root element of the document must contain an xmlns declaration for the XHTML namespace. Examples:
  <html xmlns=  "http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<h:html xmlns:h="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  1. There must be a DOCTYPE declaration in the document prior to the root element.
  2. The DTD subset must not be used to override any parameter entities in the DTD.
  3. An XML declaration on top of the file is mandatory if the character set used is different from UTF-8 or UTF-16.

XHTML Versions

XHTML 1.0 (26 jan 2000, revised 1 Aug 2002)
  • XHTML 1.0 transitional
  • XHTML 1.0 strict
  • XHTML 1.0 frameset
XHTML 1.1 - Module-based XHTML
  • XHTML Basic 1.1 is a mini-version of XHTML 1.0 for small devices (e.g. cell phones and PDAs). In principle, a successor for older WAP standards
XHTML 2.x


Example

<?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" xml:lang="en" lang="en">
 <head>
   <title>Virtual Library</title>
 </head>
 <body>
   <p>Moved to <a href="http://example.org/">example.org</a>.</p>
 </body>
</html>

Composite documents

  • XHTML can include other namespaced languages, e.g. SVG or MathML or your own XML. However, for the moment it is not possible to validate composite documents.
MathML example
<?xml version="1.0" encoding="iso-8859-1"?>
<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml">
 <xhtml:body>
   <xhtml:h1>A Compound Document</xhtml:h1>
   <xhtml:p>A simple formula using MathML in XHTML.</xhtml:p>
   <mathml:math xmlns:mathml="http://www.w3.org/1998/Math/MathML">
     <mathml:mrow>
       <mathml:msqrt>
         <mathml:mn>49</mathml:mn>
       </mathml:msqrt>
       <mathml:mo>=</mathml:mo>
       <mathml:mn>7</mathml:mn>
     </mathml:mrow>
   </mathml:math>
 </xhtml:body>
</xhtml:html>


  • It is also possible to include XHTML tags in any XML document markup. E.g. here is an example:
<?xml version="1.0" ?>
<?xml-stylesheet href="xml_plus_xhtml.css" type="text/css"?>
<page xmlns:html="http://www.w3.org/1999/xhtml" updated="jan 2007">
<title>Hello friend</title>
<list>
  <!-- we use an HTML tag below to include a picture -->
  <html:img src="photo.jpg"/>
  <item price="10"> White plate </item> 
  <item price="20"> Gold plate </item> 
  <item price="15"> Silver plate </item> 
</list>
<comment> Written by <html:a href="http://tecfa.unige.ch/tecfa-people/schneider.html">DKS/Tecfa</html:a> , feb 2007 </comment>
</page>

Current issues

  • XHTML is badly supported by IE6 and IE7. I.e. current (15:02, 12 March 2007 (MET)) Microsoft browser do not recognize the application/xhtml+xml mimetype, which makes it difficult to include XSLT stylesheets or other languages such as SVG or MathML.

There are workarounds to somewhat deal with IE 6/7:

  • Using server-side rewrite rules
  • Serve a document as either HTML or XML and use *.htm *.html or *.xml file extensions from a standard web server. If you send XHTML as simple HTML files you will loose all XML-related advantages.

Links

Standards

On-line tools