XHTML Interview Question and Answer

There are many things that you can do ahead of time to prepare for the interviewing process, and move yourself a step above of the competition. Updating your resume and reviewing frequently asked interview questions can be very effective, and goes a long way in getting the most out of your interview.

What's XHTML Validation?

An XHTML document is validated against a Document Type Definition.
Validate XHTML With A DTD

An XHTML document is validated against a Document Type Definition (DTD). Before an XHTML file can be properly validated, a correct DTD must be added as the first line of the file.

The Strict DTD includes elements and attributes that have not been deprecated or do not appear in framesets:

!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"

The Transitional DTD includes everything in the strict DTD plus deprecated elements and attributes:

!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"

The Frameset DTD includes everything in the transitional DTD plus frames as well:

!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"

This is a simple XHTML document:

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>simple document</title>
</head>
<body>
<p>a simple paragraph</p>
</body>
</html>

 

Ampersands in hrefs must convert "&" to "&amp;" in the URI

<a href="http://www.phonelists.com/cgi-bin/Handler.pl?ListID=Test&Password=test&action=View">Sample List</a>

becomes
<a href="http://www.phonelists.com/cgi-bin/Handler.pl?ListID=Test&Password=test&action=View">Sample List</a>

# The attribute "name" becomes "id" when used for a locator inside a document

For example, to reference a section within a document with a URI, we usually do something like
"<a href="favoriteAnimals.html#meerkats">Meerkats</a>"

Inside the referenced section,
<a name="meerkats"><h2>Meerkats of Africa</h2></a>

becomes
<a id="meerkats"><h2>Meerkats of Africa</h2></a>
or better yet for backwards compatibility:
<a id="meerkats" name="meerkats"><h2>Meerkats of Africa</h2></a>
# Tidy
tidy is a tool to automatically convert HTML to XHTML. You can find it at http://www.w3.org/People/Raggett/tidy/.

 

What's about an assumption with XHTML?

Serving XHTML with a MIME type of text/html is wrong. The whole point of XHTML is that it's XML so that you can benefit from namespaces and the like. If you serve it as text/html, you can't:
In particular, ‘text/html' is NOT suitable for XHTML Family document types that adds elements and attributes from foreign namespaces, such as XHTML+MathML [XHTML+MathML].
Source: http://www.w3.org/TR/xhtml-media-types/#text-html
Two choices:
1. XHTML 1.0 served as application/xhtml+xml to conforming UAs, and text/html to Internet Explorer
2. HTML 4.01, served as text/html
XHTML 1.1 is not an option because it mandates a MIME type of application/xhtml+xml which is incompatible with Internet Explorer