Wireless Markup Language (WML) Tutorial

Creating Dynamic Content

You can create dynamic WML documents with any server side language such as ASP, PHP, PERL, etc. The only thing you need to do is ensure the content type has been set for WML.

In ASP, you set the content type through the Response object.

Setting the content type with ASP

Response.ContentType = "text/vnd.wap.wml"

In PHP, you set the content type through the header function.

Setting the content type with PHP

header("Content-type: text/vnd.wap.wml");

A Search Page

The following describes how to create a search page for a WAP device. The first thing we need to consider is how we'll be sending data from the WML document to the server. By default, the input element uses the GET HTTP submission method. This isn't an issue with PHP, but with ASP it will mean the data will need to be retrieved through the Request object's QueryString collection. This isn't a problem, but to illustrate the difference, the following example uses the POST method to send the data. The data will need to be retrieved through the Request object's Form collection with ASP when data is submitted using this method.


<?xml version="1.0" encoding="iso-8859-1" ?>
<card id="index" title="Search Term">
<do type="accept" label="Search Term">
    <go href="terms.asp" method="post">
        <postfield name="term" value="$term"/>
    Enter a search term:
    <input type="text" name="term" value=""/>

The following is an ASP document to perform the search, and return a WML document.


<%@ language="vbscript" %>
<% Option Explicit %>
<% Response.ContentType = "text/vnd.wap.wml" %>
<!-- #include file="adovbs.inc" -->
    Dim objDB, objRS, strConnect, strDBVirtualPath, strDBLocation, strSQL
    Dim strTerm, strDescription, counter
    strConnect="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBLocation
    Set objDB = Server.CreateObject("ADODB.Connection")
    objDB.Open strConnect
    Set objRS = Server.CreateObject("ADODB.RecordSet")
    ' Get the search term. This would be Request.QueryString("term") if
    ' no method had been specified for the input element
    strTerm = Request.Form("term")
    strSQL = "SELECT * FROM Terms WHERE [Term] LIKE '%" & strTerm & "%'"
    objRS.Open strSQL, objDB, adOpenStatic, adLockReadOnly, adCmdText
<?xml version="1.0" encoding="iso-8859-1" ?>
<card id="term" title="Terms">
<do type="prev" label="Back">
    If objRS.EOF Then
        ' No terms found in the recordset
        Response.Write "Unable to retrieve any records like " & strTerm
        Response.Write "Terms with <em>" & strTerm & "</em><br/>"
        ' Get each term that matches
        Do While NOT objRS.EOF
            counter = counter + 1
            Response.Write "<em>" & objRS.Fields("Term").Value & "</em><br/>"
            strDescription = Server.HTMLEncode(objRS.Fields("Description").Value)
            Response.Write  strDescription & "<br/>"
            Response.Write "---<br/>"
        Response.Write "Retrieved " & counter & " term(s) containing " & strTerm
    End If
    ' Tidy up
    Set objRS = Nothing
    Set objDB = Nothing

You can see this script in action at: http://www.juicystudio.com/search.wml

You might also like...


About the author

Gez Lemon United Kingdom

I'm available for contract work. Please visit Juicify for details.

Interested in writing for us? Find out more.


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The most exciting phrase to hear in science, the one that heralds new discoveries, is not 'Eureka!' but 'That's funny...'” - Isaac Asimov