{"id":228,"date":"2007-09-18T00:00:00","date_gmt":"2007-09-18T00:00:00","guid":{"rendered":"http:\/\/www.strongd.net\/?p=228"},"modified":"2007-09-18T00:00:00","modified_gmt":"2007-09-18T00:00:00","slug":"XHTML MP MIME Types and File Extension","status":"publish","type":"post","link":"https:\/\/www.strongd.net\/?p=228","title":{"rendered":"XHTML MP MIME Types and File Extension"},"content":{"rendered":"<p><H2><A name=\"6.1.MIME Types|outline\"><\/A>MIME Types<\/H2><br \/>\n<P><FONT class=mainText>The following three MIME types can be used for XHTML MP documents:<\/FONT><\/P><br \/>\n<OL><br \/>\n<LI><br \/>\n<P><FONT class=mainText>application\/vnd.wap.xhtml+xml<\/FONT><\/P><br \/>\n<LI><br \/>\n<P><FONT class=mainText>application\/xhtml+xml<\/FONT><\/P><br \/>\n<LI><br \/>\n<P><FONT class=mainText>text\/html<\/FONT><\/P><\/LI><\/OL><br \/>\n<DIV><br \/>\n<P><FONT class=mainText>The MIME type specified by the <A href=\"http:\/\/www.openmobilealliance.org\/\">Open Mobile Alliance [OMA]<\/A> for XHTML MP documents is &#8220;application\/vnd.wap.xhtml+xml&#8221;. This MIME type is required for some WAP browsers (for example, some Nokia Series 60 browsers) to display XHTML MP documents correctly.<\/FONT><\/P><br \/>\n<P><FONT class=mainText>Another choice is the &#8220;application\/xhtml+xml&#8221; MIME type. It is the MIME type for XHTML Family document types.<\/FONT><\/P><br \/>\n<P><FONT class=mainText>The &#8220;text\/html&#8221; MIME type is also a possible choice. It is the MIME type of HTML documents. Using &#8220;text\/html&#8221; 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 &#8220;application\/vnd.wap.xhtml+xml&#8221; or &#8220;application\/xhtml+xml&#8221; 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.<\/FONT><\/P><br \/>\n<H3><A name=\"6.1.1.Choosing MIME Types Dynamically|outline\"><\/A>Choosing MIME Types Dynamically<\/H3><br \/>\n<P><FONT class=mainText>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 &#8220;application\/vnd.wap.xhtml+xml&#8221; MIME type, then all your XHTML MP documents will be delivered as &#8220;application\/vnd.wap.xhtml+xml&#8221; to this user agent.<\/FONT><\/P><br \/>\n<P><FONT class=mainText>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:<\/FONT><\/P><br \/>\n<OL><br \/>\n<LI><br \/>\n<P><FONT class=mainText>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.<\/FONT><\/P><br \/>\n<LI><br \/>\n<P><FONT class=mainText>If the accept header value contains &#8220;application\/vnd.wap.xhtml+xml&#8221;, set the MIME type of the XHTML MP document to &#8220;application\/vnd.wap.xhtml+xml&#8221;.<BR>Else if the accept header value contains &#8220;application\/xhtml+xml&#8221;, set the MIME type of the XHTML MP document to &#8220;application\/xhtml+xml&#8221;.<BR>Else set the MIME type of the XHTML MP document to &#8220;text\/html&#8221;.<\/FONT><\/P><\/LI><\/OL><br \/>\n<P><FONT class=mainText>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.<\/FONT><\/P><br \/>\n<P><BR><\/P><br \/>\n<P><FONT class=codeText>&lt;%<BR>String acceptHeader = request.getHeader(&#8220;accept&#8221;);<BR><BR>if (acceptHeader.indexOf(&#8220;application\/vnd.wap.xhtml+xml&#8221;) != -1)<BR>&nbsp;&nbsp;response.setContentType(&#8220;application\/vnd.wap.xhtml+xml&#8221;);<BR>else if (acceptHeader.indexOf(&#8220;application\/xhtml+xml&#8221;) != -1)<BR>&nbsp;&nbsp;response.setContentType(&#8220;application\/xhtml+xml&#8221;);<BR>else<BR>&nbsp;&nbsp;response.setContentType(&#8220;text\/html&#8221;);<BR>%&gt;<\/FONT><\/P><br \/>\n<P><BR><\/P><br \/>\n<P><FONT class=mainText>Here are some descriptions of the above JSP code:<\/FONT><\/P><br \/>\n<P><FONT class=mainText>1. The accept header value is obtained from the HTTP request. It is then stored in the variable <I>acceptHeader<\/I>.<\/FONT><\/P><br \/>\n<P><BR><\/P><br \/>\n<P><FONT class=codeText>String acceptHeader = request.getHeader(&#8220;accept&#8221;);<\/FONT><\/P><br \/>\n<P><BR><\/P><br \/>\n<P><FONT class=mainText>2. After that, the variable <I>acceptHeader<\/I> is checked to see if it contains the words &#8220;application\/vnd.wap.xhtml+xml&#8221; or &#8220;application\/xhtml+xml&#8221;. The <I>indexOf(String str)<\/I> method of the String object returns the index of the first occurrence of the <I>str<\/I> substring. If <I>str<\/I> is not found, -1 is returned by the <I>indexOf(String str)<\/I> method. In other words, if <I>str<\/I> is found, the return value will not be -1.<\/FONT><\/P><br \/>\n<P><BR><\/P><br \/>\n<P><FONT class=codeText>if (acceptHeader.indexOf(&#8220;application\/vnd.wap.xhtml+xml&#8221;) != -1)<BR>&#8230;<BR>else if (acceptHeader.indexOf(&#8220;application\/xhtml+xml&#8221;) != -1)<BR>&#8230;<\/FONT><\/P><br \/>\n<P><BR><\/P><br \/>\n<P><FONT class=mainText>3. The method<\/FONT><\/P><br \/>\n<P><FONT class=codeText>response.setContentType(&#8230;);<\/FONT><\/P><br \/>\n<P><FONT class=mainText>is used to set the MIME type of a document.<\/FONT><\/P><br \/>\n<P><BR><\/P><br \/>\n<P><FONT class=mainText>The following example illustrates how to use the JSP code in an actual XHTML MP document. What you need to do is very simple &#8212; Just copy and paste the JSP code into the XHTML MP document and use &#8220;.jsp&#8221; as the file extension. (The XHTML MP markup in this example will be discussed in detail in the following sections.)<\/FONT><\/P><br \/>\n<P>&nbsp;<\/P><br \/>\n<P><FONT color=#0000ff>&lt;?xml version=&#8221;1.0&#8243;?&gt;<BR>&lt;!DOCTYPE html PUBLIC &#8220;-\/\/WAPFORUM\/\/DTD XHTML Mobile 1.0\/\/EN&#8221; &#8220;<\/FONT><A href=\"http:\/\/www.wapforum.org\/DTD\/xhtml-mobile10.dtd\"><FONT color=#0000ff>http:\/\/www.wapforum.org\/DTD\/xhtml-mobile10.dtd<\/FONT><\/A><FONT color=#0000ff>&#8220;&gt;<\/FONT><\/P><br \/>\n<P><FONT color=#0000ff>&lt;html xmlns=&#8221;<\/FONT><A href=\"http:\/\/www.w3.org\/1999\/xhtml\"><FONT color=#0000ff>http:\/\/www.w3.org\/1999\/xhtml<\/FONT><\/A><FONT color=#0000ff>&#8220;&gt;<BR>&nbsp; &lt;head&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;title&gt;XHTML MP Tutorial&lt;\/title&gt;<BR>&nbsp; &lt;\/head&gt;<\/FONT><\/P><br \/>\n<P><FONT color=#0000ff>&nbsp; &lt;body&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;p&gt;Hello world. Welcome to our XHTML MP tutorial.&lt;\/p&gt;<BR>&nbsp; &lt;\/body&gt;<BR>&lt;\/html&gt;<BR><\/FONT><STRONG><FONT color=#0000ff>&lt;%<BR>String acceptHeader = request.getHeader(&#8220;accept&#8221;);<\/FONT><\/STRONG><\/P><br \/>\n<P><FONT color=#a2a2a2><STRONG><FONT color=#0000ff>if (acceptHeader.indexOf(&#8220;application\/vnd.wap.xhtml+xml&#8221;) != -1)<BR>&nbsp; response.setContentType(&#8220;application\/vnd.wap.xhtml+xml&#8221;);<BR>else if (acceptHeader.indexOf(&#8220;application\/xhtml+xml&#8221;) != -1)<BR>&nbsp; response.setContentType(&#8220;application\/xhtml+xml&#8221;);<BR>else<BR>&nbsp; response.setContentType(&#8220;text\/html&#8221;);<BR>%&gt;<\/FONT><BR><\/STRONG><\/FONT><\/P><br \/>\n<P><FONT color=#a2a2a2><FONT color=#000000><STRONG>File Extension<\/STRONG><\/FONT><\/FONT><\/P><FONT color=#a2a2a2><br \/>\n<P><FONT class=mainText color=#000000>The file extensions of static XHTML MP documents are &#8220;.xhtml&#8221;, &#8220;.html&#8221; and &#8220;.htm&#8221; 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&#8217;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 &#8220;.php&#8221;, while that used by SSI is &#8220;.shtml&#8221;.<\/FONT><\/P><\/FONT><\/DIV><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8220;application\/vnd.wap.xhtml+xml&#8221;. This MIME type is required for some WAP browsers (for example, some Nokia Series 60 browsers) to display XHTML MP documents correctly. &hellip; <a href=\"https:\/\/www.strongd.net\/?p=228\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">XHTML MP MIME Types and File Extension<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-228","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/228","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=228"}],"version-history":[{"count":0,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/228\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=228"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}