Saturday, September 17, 2005

How to Make Drupal 4.6.3 render XML, MathML, with the Chameleon Theme

Update: If you are really interested in MathML, I recommend using XML all the way through authoring and publishing. See MMADE's samples page for some results of this route.

In chameleon.theme, change:

$output = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"\">\n"; $output .= "<html xmlns=\"\" lang=\"$language\" xml:lang=\"$language\">\n";


if((stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml"))||(stristr($_SERVER["HTTP_USER_AGENT"],"Validator"))) { $output = "<?xml version=\"1.0\"?>\n"; $output .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN\" \"\">\n"; $output .= "<html xmlns=\"\" xml:lang=\"$language\">\n"; } else { $output = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"\">\n"; $output .= "<html xmlns=\"\" lang=\"$language\" xml:lang=\"$language\">\n"; }

In, change:

$output = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n";


if((stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml"))||(stristr($_SERVER["HTTP_USER_AGENT"],"Validator"))) { $output = "<meta http-equiv=\"Content-Type\" content=\"application/xhtml+xml; charset=utf-8\" />\n"; } else { $output = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n"; }


drupal_set_header('Content-Type: text/html; charset=utf-8');


if((stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml"))||(stristr($_SERVER["HTTP_USER_AGENT"],"Validator"))) { drupal_set_header('Content-Type: application/xhtml+xml; charset=utf-8'); } else { drupal_set_header('Content-Type: text/html; charset=utf-8'); }

Now, load IE, since it does not emit application/xhtml+xml in HTTP_ACCEPT. Clear all of your cached data, so that IE does not use the old data for your site. Load "" in IE. Load about:blank in IE. Clear all of your cached data again. Shut down IE. Reload IE. Reload your site in IE. Log in. Change your site theme to chameleon (or away from it and back again). Log out. Clear the other browser's cache. You're now done.

Several caveats exist with this solution: Drupal frequently renders non-well-formed pages. These could include the administrative logs screen, any story in which a tease "cuts" a tag, or just any node that contains non-well-formed tags. Until Drupal comes up with a way to fix them, automatic teasers can be eliminated by setting the tease length to unlimited, with subsequent regeneration of the problem teasers, or by judicious use of <!--break-->. All node items must be validated by someone working in an application/xhtml+xml browser, etc.

Credit for the idea to also serve XML pages to validators goes to Brian Puccio for his post on Drupal and XML. Thanks also go to eldarin for helping me sort out the headers.

Thursday, September 1, 2005

For those who want to know what Kettering's beautiful side looks like

For those who want to know what Kettering's beautiful side looks like, please see Joel's post "The Landscape of Kettering".