Library tutorials & articles

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

<?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.

search.wml

<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
    "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="index" title="Search Term">
<do type="accept" label="Search Term">
    <go href="terms.asp" method="post">
        <postfield name="term" value="$term"/>
    </go>
</do>
<p>
    Enter a search term:
    <input type="text" name="term" value=""/>
</p>
</card>
</wml>

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

terms.asp

<%@ 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
    strDBVirtualPath="db/terms.mdb"
    strDBLocation=Server.Mappath(strDBVirtualPath)
    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" ?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
    "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="term" title="Terms">
<do type="prev" label="Back">
    <prev/>
</do>
<p>
<%
    If objRS.EOF Then
        ' No terms found in the recordset
        Response.Write "Unable to retrieve any records like " & strTerm
    Else
        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/>"
            objRS.MoveNext
        Loop
        Response.Write "Retrieved " & counter & " term(s) containing " & strTerm
    End If
    ' Tidy up
    objRS.Close
    Set objRS = Nothing
    objDB.Close
    Set objDB = Nothing
%>
</p>
</card>
</wml>

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

Comments

  1. 19 Jul 2005 at 12:13

    hi
            I am Jagannath working as Sr.Programmer in Med Write India Ltd. I have one doubt that how to search the latest modified file on the stipulated time and date.If you will help me then i will be happy


    Bye
    Jagannath
    my alternate email address is b_jagan03@yahoo.co.in
    Phno : 09849654314



  2. 16 Feb 2004 at 00:49

    Nice articlae but require more info on this

  3. 01 Jan 1999 at 00:00

    This thread is for discussions of Wireless Markup Language (WML) Tutorial.

Leave a comment

Sign in or Join us (it's free).

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

Related podcasts

  • EarthClassMail.com - Moving from LAMP to .NET 3.5

    Scott chats with Matt Davis, architect at EarthClassMail.com, about their move from a LAMP stack (Linux/Apache/mysql/PHP) to .NET 3.5. What's working, what's not, and what kinds of issues are they running into as their architect their solution.

Events coming up

  • Dec 3

    The Auckland PHP December meetup

    Auckland, New Zealand

    Topic: Magento E-Commerce platform Speaker: Robert Popovic, LERO9, Robert is the Technical Director and co-founder of LERO9. Robert attended the Electrotechnical Faculty at The University of Belgrade where he graduated with a Masters in Computer Science and Information Technology. Robert has worked exclusively in the field of web and software development throughout his career.

We'd love to hear what you think! Submit ideas or give us feedback