Serving XML and XHTML with Classic ASP
21 January 2007 | Posted by Jeffrey Barke | No comments
Since I talked about setting the MIME type with PHP, I figured I might as well give an example of how to do it with Classic ASP as well.
Serving XML:
Response.ContentType = "text/html"
Response.Charset = "utf-8"
Serving XHTML:
If InStr(Request.ServerVariables("HTTP_ACCEPT"), "application/xhtml+xml") > 0 Then
Response.ContentType = "application/xhtml+xml"
Else
Response.ContentType = "text/html"
End If
Response.Charset = "utf-8"
Serving XML and XHTML with PHP
21 January 2007 | Posted by Jeffrey Barke | 1 comment
In PHP, the MIME type is set through the header function (note the header function must be called prior to outputting anything to the browser).
To correctly serve XML, call the header function with the following arguments:
header('Content-Type: text/xml; charset=utf-8');
Correctly serving XHTML is a bit more complicated. The $_SERVER array contains the server variables, allowing us to interrogate the Accept HTTP header:
header('Vary: Accept');
if (stristr($_SERVER[HTTP_ACCEPT], 'application/xhtml+xml')) {
header('Content-Type: application/xhtml+xml; charset=utf-8');
} else {
header('Content-Type: text/html; charset=utf-8');
}

