Skip to page content or skip to Accesskey List.
Search evolt.org
evolt.org login: or register

Work

Main Page Content

WAP for fun and profit - Part 1 - Basic WML format

Rated 3.56 (Ratings: 3) (Add your rating)

Log in to add a comment
(6 comments so far)

Want more?

 
Picture of bennettpr

Paul Bennett

Member info | Full bio

User since: September 17, 2002

Last login: December 17, 2008

Articles written: 1

Why WAP?

For plain-old-web-browsing, staring at a tiny monochrome screen offers little in the way of excitement. Where WAP can come into good use is in the creation of business applications for remote users. Consider the following situations:

  1. A large plumbing firm who wastes many hours having their plumbers travel back to the office to get new job information.
  2. Technicians needing to get data back from a remote location to a central server in real time.
  3. A large city council looking to streamline car parking services and kill off those pesky meters.
In all these cases, WAP has been used to provide a simple and (largely) device independent solution. For example:
  1. Each plumber is given a WAP capable phone and can receive their job information while in the field, they can also input data back to the central server, such as parts used and time spent.
  2. Technicians can input data directly into the WAP device and have the master database updated immediately.
  3. WAP is used as a medium to provide customers a wireless way to set parking times, and update their parking without having to use a parking meter.

Your first WML page

<?php 
header("Content-type: text/vnd.wap.wml"); ?>
echo "<?xml version=\"1.0\"?>"; // this is only added server side in this example to avoid php trying to parse the xml tag
?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
  <card id="card1" title="Basic WAP Page"> 
   <p>
    <big>		
     My first Wap page
    </big>
    <br/>	
    <small>
     hello!
    </small>
   </p>
  </card>
</wml>

How it all works

The document headers

The first thing we notice is that WML has an XML-based structure. (This will be familiar to anyone who has coded in XHTML.) WAP devices are extremely strict and will not display malformed content. All you will get is a generic error message, so always double check and test at each step of your development. At the server side, (in PHP for this example) we have added a content-type header (to correctly inform the device of the content that follows), then an xml declaration to inform the browser of the structure of the document (well-formed xml). Before the first <wml> tag we add a document type definition. (Currently there is only one document type definition for WML 1.0.) According to the wapforum, a document type definition "is a formal description in XML declaration syntax of a particular type of document. It sets out what names are to be used for the different types of element, where they may occur, and how they all fit together."

The document structure

Similarly to an HTML or XHTML document, the actual content is surrounded by <wml></wml> tags. One difference in WML is that each page is called a "card", and several (or even only one) "card" comprise a "deck". Only one card is displayed at a time and can link to other "cards" in the "deck" via anchor links which reference the id of the card you wish to display. For example a link like this:

&lt;a href="#anotherCard"&gt;Go to the next card&lt;/a&gt;

will direct the user to the card in the same deck where the card id="anotherCard"

Please Note!

  1. All displayed content in the WML page must be contained in <p></p> tags or it will not be recognised as well formed and will not display.
  2. The card id cannot be a single digit or character, there must be at least 2 digits (alpha or numeric) in the card id for it to allow the page to be rendered correctly.

Getting server side processing going.

Ok, we can display a static page, but how can we hook this up to interact with our database, or get something more exciting happening?

WML has a different way of POSTing or GETTING variables to the server. In this example we will look at the old POST method and how to post variables to the server.

<?php 
header("Content-type: text/vnd.wap.wml"); ?>
echo "<?xml version=\"1.0\"?>"; // this is only added server side in this example to avoid php trying to parse the xml tag
?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
  <card id="card1" title="WML Post to server">  
   <p>		 
    <big>
     Pick your favourtite colour :
    </big>			
    <br/>
    <select name="favColour">
     <option value="red">red</option>
     <option value="yellow">yellow</option>
     <option value="pink">pink</option>
     <option value="green">green</option>
    </select>
    <do type="accept" name="next" label="save">
     <go href="processColour.php" method="post">
      <postfield name="userColour" value="$(favColour)"/>
     </go>
    </do>
   </p> 
  </card>
 </wml>
	  

How WML "forms" and submitting data works.

Boy does that select list look familiar or what? Yes WML supports the select list tag as well as the same option tag format as HTML. The difference here the code for posting the data to the server.

Firstly, the "do" tag defines what type of task is to be performed. Basically this "accept" task causes the label "save" to be displayed in the browser screen (usually at the bottom left).

Secondly, the "go" tag defines the url that the data is to be sent to and the method by which it is to be sent ("post" or "get" - in lowercase.). This is the most similar to the HTML "form" tag.

Thirdly, the "postfield" tag defines which form fields will post data to the server. Not all form fields are automatically sent to the server like in HTML, they must be defined in the "postfield" tags or no data will be sent to the server. The postfield tag must have a different name than the form value it will send. In this example, the name of the variable that will be sent to the server is "userColour", which has the value of "$(favColour)" assigned to it. This is WML''''s way of saying "take the value of ''''favColour'''' and post it to the server with the name ''''userColour'''' ". Cumbersome yes, but that''''s the way it is at the moment, people.

Summary

So far we have covered basic WML formatting and begun to see how we can interact with the server. In Part two we will examine some more of WML''''s input options, as well as navigation and menu structure.
Although WAP does still has many pitfalls and weaknesses (such as security, usability and browser discrepancies - does this remind anyone of the early internet?), it can already provide solutions to some of our customers. We, as developers, just need to help some customers see how they can use this technology to enhance their existing processes.

Paul has worked on the internets since 2001. He lives in New Zealand with his wife, 3.6 children and a cat that won't go away.

PHP and XML

Submitted by tupholme on March 20, 2003 - 12:13.

PHP won't try to parse the XML declaration processing instruction (<?xml) if PHP short open tags are disabled, meaning you can write it in-line just like you would static HTML or WML. This is configured using the short_open_tag directive in php.ini, httpd.conf or .htaccess files; see the PHP manual page for more details. The same rule also applies to other processing instructions such as <?xml-stylesheet.

The consequence of disabling short open tags is that you must always use <?php because <? by itself won't work any more. Troublesome if you've got a lot of old code to convert, but it's worth getting into the habit of doing it because the need to work with XML is only going to increase.

login or register to post comments

PHP and XML; data limits

Submitted by lauri on March 20, 2003 - 14:27.

Hi Paul,

Nice intro article, I hope we will get to see part 2 soon.

In response to tupholme, there is a solution to that - cheap one, I admit - you echo the first line of the document (

<?php
 
echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"
?>
\n"; ?>) in case you cannot do anything about server configuration. It can help you out in some cases, but it's still just a lousy hack, so don't make a habit out of using it if you can help it.

Btw, Paul, I hope you will cover max deck sizes and card sizes in the articles to come that different devices support (this is an issue that many people seem to bump into and can't find a lot of information on the web about it... just finished getting a person up to date on this last week).

Also, as far as my experience goes with programming sites that dynamically generate WAP sites, marketing people like to hear about options 'bout using colors in images and text. Phones with color displays is a relatively new thing out there, but there are some solutions (both standards and in some cases unique solutions for each phone or device) for it.

Good luck on the second part!

login or register to post comments

Another WAP emulator

Submitted by munger on March 21, 2003 - 17:07.

About three years ago when I needed an emulator to test a WML-based contact app, I used the Deck-it cell phone emulator, which is written in Perl/TK. It's free, and there are executables for Linux and Windows, but the source is also available.

login or register to post comments

Data limits

Submitted by tupholme on March 22, 2003 - 03:16.

I had problems with data limits when I did a WAP project. I think the standard limit for a deck is about 1,400 bytes! That usually means you have to consider not only how many cards you can fit into a deck, but whether or not your content will fit onto a single card at all - as you may have noticed when using WAP sites, a single piece of content is often (arbitrarily) split over several screens.

login or register to post comments

Data limits

Submitted by lauri on March 22, 2003 - 06:20.

Yeah, 1400 bytes is roughly a fair esimate (it's a bit more, but not significantly). Actually some devices should support 8000 bytes and in some cases even more, but in my experience, quite a few mobile service providers limit it to 1400 to make sure that nobody gets left out.

login or register to post comments

max deck sizes

Submitted by bennettpr on July 14, 2004 - 19:16.

There is a small data sheet here: http://www.stv.ee/~kunashir/nokia.html, but I would also agree with the suggestions to trim deck sizes to a standard minimum.

login or register to post comments

The access keys for this page are: ALT (Control on a Mac) plus:

evolt.orgEvolt.org is an all-volunteer resource for web developers made up of a discussion list, a browser archive, and member-submitted articles. This article is the property of its author, please do not redistribute or use elsewhere without checking with the author.