Transcript XHTML

CSCI/CINF 4230
XHTML
Instructor: Charles Moen
XHTML (W3Schools, Schultz, Wikipedia)
XHTML
 A stricter version of HTML
 Extensible HTML
 The XHTML specification is maintained by the
World Wide Web Consortium (W3C)
 Current version is 1.1, but browsers support only
XHTML 1.0
 HTML 4.01 with stricter syntax rules
2
XHTML (W3Schools, Schultz)
XHTML Syntax Rules
 All tag names and attribute names must be lower case
 Elements must always be closed
 Elements must be properly nested
 All attribute values must be surrounded with quotes
 All attributes must have a value
 The DOCTYPE is required
 Some elements are mandatory
 Some elements are deprecated
3
XHTML (W3Schools, Wikipedia, W3C)
Why XHTML?
 With HTML, browsers were programmed to
overlook “coding errors,” such as improper
nesting
•
•
Required more browser resources
Web developers were often unaware of errors because they
were masked by the browser
 Benefits of more consistent syntax rules
•
•
•
Reduce the demands on user agents
Well-formed code that is more compatible
Code is displayed more consistently by all browsers
4
XHTML
HTML vs. XHTML
Both of these pages display the same content
<HTML>
<HEAD>
<TITLE>Old HTML</TITLE>
</HEAD>
<BODY>
<H1>Thursday <EM>Specials</EM></H1>
<P>Double coupons today!
<BR>
<OL>
<LI>Vegetables
<UL>
<LI>Green beans
<LI>Broccoli
<LI>Spinach
</UL>
<LI>Fruit
</OL>
</BODY>
</HTML>
Valid HTML
Valid XHTML
<!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>An XHTML Page</title>
<meta http-equiv="content-type"
content="text/html;charset=utf-8" />
</head>
<body>
<h1>Thursday <em>Specials</em></h1>
<p>Double coupons today!</p>
<br />
<ol>
<li>Vegetables
<ul>
<li>Green beans</li>
<li>Broccoli</li>
<li>Spinach</li>
</ul>
</li>
<li>Fruit</li>
</ol>
</body>
</html>
5
XHTML (W3Schools, Schultz, W3C)
Three Types
For your homework, use the “strict” XHTML 1.0 DOCTYPE, unless your page uses
frames (see below)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
For your homework pages that use frames, use the “frameset” XHTML 1.0 DOCTYPE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
More relaxed, allowing some deprecated features: “transitional” XHTML 1.0 DOCTYPE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
XHTML (W3C)
Markup Validation
 A markup validator checks whether your markup
code follows the standards; it checks the following:
•
•
•
•
Only allowed elements are used
Tag names are spelled correctly
Opening and closing tags are matched
No grammar rules are violated
 W3C Markup Validation Service
http://validator.w3.org
All homework assignments for this course must be validated, using the W3C
Markup Validator, and they must have a W3C validator link on the page
7
References
Ding, Wei, “XHTML” UHCL lecture slides, 2008.
Schultz, David and Craig Cook, Beginning HTML with CSS and XHTML: Modern Guide
and Reference. Apress, 2007.
W3C. (2007). “Recommended list of DTDs”, [Online].
Available: http://www.w3.org/QA/2002/04/valid-dtd-list.html
W3Schools Online Web Tutorials. "Learn XHTML". [Online].
Available: http://www.w3schools.com/xhtml/default.asp
Wikipedia. “XHTML”. [Online]. Available:http://en.wikipedia.org/wiki/XHTML
8