The XHTML WYSIWYG Editor For Desktop & Web Applications

Content Negotiation

Content Negotiation: Setting The Media Type For Web Pages

XHTML 1.1 should be served as XML to Web browsers that support the application/xhtml+xml media type. Most modern browsers such as Firefox, Opera and Safari do support the application/xhtml+xml media type, but Internet Explorer is lagging behind the times. The IE development team has indicated that they plan to support this media type in the future, but until they do, xstandard.com will serve XHTML 1.0 Strict as HTML to browsers such as IE, using a technique called "content negotiation".

Image: XHTML 1.1 button.You can implement content negotiation for your own site if your Web site uses server-side scripting languages such as PHP, ASP, etc. Below are examples of how to set this up in different scripting languages. If you adopt this strategy, rest assured that your Web site continues to be XHTML 1.1 compliant. You can also continue to display the XHTML 1.1 compliance button that tells visitors that you have taken care to create an inter-operable Web site.

Setting The Media Type

PHP

  1. $accept = $_SERVER["HTTP_ACCEPT"];
  2. $ua = $_SERVER["HTTP_USER_AGENT"];
  3. if (isset($accept) && isset($ua)) {
  4. if (stristr($accept, "application/xhtml+xml") || stristr($ua, "W3C_Validator")) {
  5. header("Content-Type: application/xhtml+xml");
  6. }
  7. }

Active Server Pages

  1. Dim strAccept, strUA
  2. strAccept = Request.ServerVariables("HTTP_ACCEPT").Item
  3. strUA = Request.ServerVariables("HTTP_USER_AGENT").Item
  4. If InStr(1, strAccept, "application/xhtml+xml") > 0 Or InStr(1, strUA, "W3C_Validator") > 0 Then
  5. Response.ContentType = "application/xhtml+xml"
  6. End If

C# In ASP.NET

  1. string accept = Request.ServerVariables["HTTP_ACCEPT"];
  2. string ua = Request.ServerVariables["HTTP_USER_AGENT"];
  3. if (accept != null && ua != null) {
  4. if (accept.IndexOf("application/xhtml+xml") >=0 || ua.IndexOf("W3C_Validator") >= 0) {
  5. Response.ContentType = "application/xhtml+xml";
  6. }
  7. }

Declaration

You should apply the same principle and change the declaration to indicate you are serving XHTML 1.0 Strict:

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

... instead of XHTML 1.1:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  2. "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

CSS

When serving up XHTML 1.1, you can put the reference to CSS in a processing instruction. For example:

  1. <?xml-stylesheet href="my.css" type="text/css" media="screen" title="My CSS"?>

...instead of in the style element. For example:

  1. <style type="text/css">@import url('my.css');</style>