|
Make your WML pages fly© Wai Seto
Aug 1, 2000
One of the biggest advancement of HTML pages is the ability of generating pages dynamically. The ability to access database and customizing contents put web application to the next level. Static contents are useful, but dynamic contents are better. It is no different for Wireless Internet Applications. In WAP, developers can certainly use WMLScript to help in development contents. What if we want to customize contents on the fly, or allow user to query a database for data. In HTML world, developers use CGI, Common Gateway Interface, or server side script, e.g. Active Server Pages, to do so. The idea is the same for WAP. We will not talk about how CGI or server side script accessing backend database; rather we will look at couple ways to generate WML pages on the fly. Perl:
Perl is a very common tool for CGI programming. Here we have a very simple Perl script to generate WML pages:
#! /usr/bin/perl
use CGI;
$head = PrintHeader();
print $head;
print "<wml>";
print "<card id=\"Main\" title=\"Quick Welcome\">";
print "<do type=\"prev\">";
print "<prev/>";
print "</do>";
print "<do type=\"options\" label=\"Home\">";
print "<go href=\"/wml/welcome.wml\"/>";
print "</do>";
print "<p>Select<br/> <b>options</b> <br/>button</p>";
print "</card></wml>";
sub PrintHeader{
my($header);
$header = "Content-type: text/vnd.wap.wml\n\n";
$header .= "<?xml version=\"1.0\"?>";
$header .= "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\"";
$header .= " \"http://www.wapforum.org/DTD/wml_1.1.xml\">\n";
return $header;
}
The above example will generate a WML page with content type as text/vnd.wap.wml. This is all we need. Sure enough for all you perl experts, it is very easy to put Perl code to access your database and generate WML pages. Active Server Pages
A very common server side script ASP on Windows platform can also be used. The following example is the code to generate a WML page. Again, as you can probably understand now, the most important part is to generate the correct content type and WML page header.
<%
Response.Expires = 0 'Expire this page immediately
Response.CacheControl = "no-cache" 'Don't cache this page
Response.ContentType="text/vnd.wap.wml"
%>
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml12.dtd">
<wml>
<template>
<do type="prev" name="BACK" label="Back"><prev/></do>
</template>
<card id="main" title="Enter Values.">
<p>
Hello World
</p>
</card>
</wml>
With a little scripting and CGI programming, you can too make your WML pages fly. Next article, we will look at another element of WML that helps us to speed up our WML creation.
Extra: Please join the WAP Suite mailing for updates of news articles, and URLs. I will tell you when new articles are up. :) Please come to http://www.camelot.net/wap/
Go To Page:
1
2
The copyright of the article Make your WML pages fly in Wireless Internet is owned by . Permission to republish Make your WML pages fly in print or online must be granted by the author in writing.
|