XHTML MP MIME Types
and File Extension
MIME
Types
The
following three MIME types can be used for XHTML MP documents:
application/vnd.wap.xhtml+xml
application/xhtml+xml
text/html
The
MIME type specified by the Open
Mobile Alliance [OMA] for XHTML MP documents is
"application/vnd.wap.xhtml+xml". This MIME type is required
for some WAP browsers (for example, some Nokia Series 60 browsers) to
display XHTML MP documents correctly.
Another
choice is the "application/xhtml+xml" MIME type. It is the
MIME type for XHTML Family document types.
The
"text/html" MIME type is also a possible choice. It is the
MIME type of HTML documents. Using "text/html" for XHTML MP
documents has the benefit that your XHTML MP pages will be viewable
on ordinary web browsers without any problems. (Some web browsers like IE 6
do not show documents with MIME types "application/vnd.wap.xhtml+xml" or
"application/xhtml+xml" but will bring up a dialog box to let you
open the file in an external program or choose a location to save the file.) The drawback is that
the user agent will not treat your XHTML MP pages as XML documents,
which means the user agent may not complain even if the markup code
does not follow strictly the XML rules.
Choosing MIME Types
Dynamically
Another
option is to detect the MIME types that can be handled by a user
agent and choose the MIME type dynamically. For example, if your
server finds out that a certain user agent can handle the
"application/vnd.wap.xhtml+xml" MIME type, then all your
XHTML MP documents will be delivered as
"application/vnd.wap.xhtml+xml" to this user agent.
To
choose the MIME type dynamically, you need to write a few lines of
code using a server-side scripting language (e.g. ASP, JSP, Perl,
PHP). The pseudo-code is shown below:
Obtain
the accept header value of the HTTP request received. The accept
header contains all MIME types that can be handled by the client
user agent that sends the request.
If
the accept header value contains "application/vnd.wap.xhtml+xml",
set the MIME type of the XHTML MP document to
"application/vnd.wap.xhtml+xml". Else if the accept
header value contains "application/xhtml+xml", set the
MIME type of the XHTML MP document to "application/xhtml+xml". Else
set the MIME type of the XHTML MP document to "text/html".
The
following example demonstrates how to use JSP to write the code. If
you use a server-side technology other than JSP, the code will be
slightly different but the idea is the same.
<% String
acceptHeader = request.getHeader("accept");
if
(acceptHeader.indexOf("application/vnd.wap.xhtml+xml") !=
-1) response.setContentType("application/vnd.wap.xhtml+xml"); else
if (acceptHeader.indexOf("application/xhtml+xml") !=
-1) response.setContentType("application/xhtml+xml"); else response.setContentType("text/html"); %>
Here
are some descriptions of the above JSP code:
1.
The accept header value is obtained from the HTTP request. It is then
stored in the variable acceptHeader.
String
acceptHeader = request.getHeader("accept");
2.
After that, the variable acceptHeader is checked to see if it
contains the words "application/vnd.wap.xhtml+xml" or
"application/xhtml+xml". The indexOf(String str)
method of the String object returns the index of the first occurrence
of the str substring.
If str is not found,
-1 is returned by the indexOf(String str)
method. In other words, if str
is found, the return value will not be -1.
if
(acceptHeader.indexOf("application/vnd.wap.xhtml+xml") !=
-1) ... else if (acceptHeader.indexOf("application/xhtml+xml")
!= -1) ...
3.
The method
response.setContentType(...);
is
used to set the MIME type of a document.
The
following example illustrates how to use the JSP code in an actual
XHTML MP document. What you need to do is very simple -- Just copy
and paste the JSP code into the XHTML MP document and use ".jsp"
as the file extension. (The XHTML MP markup in this example will be
discussed in detail in the following sections.)
(helloWorldEg1.jsp)
<?xml
version="1.0"?> <!DOCTYPE html PUBLIC
"-//WAPFORUM//DTD XHTML Mobile 1.0//EN"
"http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml"> <head> <title>XHTML
MP Tutorial</title> </head>
<body> <p>Hello
world. Welcome to our XHTML MP
tutorial.</p> </body> </html> <% String
acceptHeader = request.getHeader("accept");
if
(acceptHeader.indexOf("application/vnd.wap.xhtml+xml") !=
-1) response.setContentType("application/vnd.wap.xhtml+xml"); else
if (acceptHeader.indexOf("application/xhtml+xml") !=
-1) response.setContentType("application/xhtml+xml"); else response.setContentType("text/html"); %>
File
Extension
The
file extensions of static XHTML MP documents are ".xhtml", ".html"
and ".htm" typically. You can use other file extensions you
like, as long as the MIME type associated with the file extension is
set correctly at your WAP server's configuration file.
If you are going to use a server-side technology such as ASP, JSP, Perl,
PHP or SSI (Server Side Includes) to add content to XHTML MP documents
dynamically, you may need to change the file extension of your XHTML MP
documents to that used by the server-side technology. For example, the
typical file extension used by PHP is ".php", while that used
by SSI is ".shtml".
|
Feedback Form (ExpandCollapse)
|
|