HTML Comes of Age: XHTML - XHTML Syntax
(Page 4 of 7 )
The semantics of XHTML elements and their attributes are defined by the current HTML 4.01 Specification. XHTML 1.0 specifies three XML document types that correspond to the three DTDs specified in HTML 4.01: Strict, Transitional, and Frameset. These XHTML DTDs are more restrictive than HTML because XML is more restrictive in its syntax. Table 1 lists the three DTDs and the DOCTYPE tag used to specify each in a Web page.
Table 1: XHTML Document Type Definitions.
XHTML 1.0 Strict: Use when you're doing all of your formatting in Cascading Style Sheets (CSS), and not using <font> and <table> tags to control how the browser displays your documents. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> |
XHTML 1.0 Transitional: Use when you need to use presentational markup in your document, so that you don't limit your audience to users with browsers that support CSS. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> |
XHTML 1.0 Frameset: Use when your documents have frames <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "DTD/xhtml1-frameset.dtd"> |
The DOCTYPE tag doesn't affect the page by itself, it just tells the browser how to validate the XHTML code in the document.
A strictly conforming XHTML 1.0 document is restricted to tags and attributes from the XHTML 1.0 namespace. (The Strict DTD moniker shouldn't be confused with 'strictly conforming' documents. Strict DTDs specify a particular format of DTD in HTML 4.01, and strictly conforming means that it fully complies with the XHTML spec.) Such a document must meet some rather exacting requirements:
• The document must validate against one of the three DTDs.
• The root element of the document must be <html>.
• The root element of the document must designate an XHTML 1.0 namespace using the xmlns attribute.
• There must be a DOCTYPE declaration in the document prior to the root element. If present, the public identifier included in the DOCTYPE declaration must reference one of the three required DTDs.
The code in Figure 1, taken from the XHMTL proposed recommendation, is an example of a minimal XHTML 1.0 document:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"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://vlib.org/">vlib.org</a>.</p >
</body>
</html>
http://www.w3.org/1999/xhtml " xml:lang="en" lang="en">
<head>
<title>Virtual Library</title>
</head>
<body>
<p>Moved to <a href=" http://vlib.org/">vlib.org</a>.</p >
</body>
</html>
Figure 1: A minimal XHTML 1.0 document, based on the Strict DTD
The spec requires that a strictly conforming document specify the XHTML namespace using the xmlns attribute, defined to be http://www.w3.org/1999/xhtml . Figure 2 shows how the XHTML namespace can be used with another namespace, and Figure 3 shows how the XHTML 1.0 namespace can be incorporated into another XML namespace. Both these examples are from the XHTML specification. The implications of this kind of flexibility are enormous, letting you build Web documents that take advantage of various features of different namespaces.
http://www.w3.org/1999/xhtml . Figure 2 shows how the XHTML namespace can be used with another namespace, and Figure 3 shows how the XHTML 1.0 namespace can be incorporated into another XML namespace. Both these examples are from the XHTML specification. The implications of this kind of flexibility are enormous, letting you build Web documents that take advantage of various features of different namespaces.
<html xmlns=" http://www.w3.org/1999/xhtml " xml:lang="en" lang="en">
<head>
<title>A Math Example</title>
</head>
<body>
<p>The following is MathML markup:</p>
<math xmlns=" http://www.w3.org/1998/Math/MathML ">
<apply> <log/>
<logbase>
<cn> 3 </cn>
</logbase>
<ci> x </ci>
</apply>
</math>
</body>
</html>
http://www.w3.org/1999/xhtml " xml:lang="en" lang="en">
<head>
<title>A Math Example</title>
</head>
<body>
<p>The following is MathML markup:</p>
<math xmlns=" http://www.w3.org/1998/Math/MathML ">
<apply> <log/>
<logbase>
<cn> 3 </cn>
</logbase>
<ci> x </ci>
</apply>
</math>
</body>
</html>
Figure 2: Example of using the XHTML 1.0 namespace with another namespace, in this case the MathXL namespace.
<?xml version="1.0" encoding="UTF-8"?>
<!-- initially, the default namespace is "books" -->
<book xmlns='urn:loc.gov:books'
xmlns:isbn='urn:ISBN:0-395-36341-6' xml:lang="en" lang="en">
<title>Cheaper by the Dozen</title>
<isbn:number>1568491379</isbn:number>
<notes>
<!-- make HTML the default namespace for a hypertext commentary -->
<p xmlns='http://www.w3.org/1999/xhtml'>
This is also available <a href=" http://www.w3.org/">online</a >.
</p>
</notes>
</book>
http://www.w3.org/">online</a >.
</p>
</notes>
</book>
Figure 3: Example of incorporating the XHTML 1.0 namespace into a custom XML namespace.
Next: Rocky Upgrade Path >>
More HTML Articles
More By Don Kiely