Home arrow Embedded Tools arrow WAP for Fun and Profit - Part 1 - Basic WML Format

WAP for Fun and Profit - Part 1 - Basic WML Format

Everyone is getting their hands on WAP devices, so why not learn the technology. In this article Paul will lend you a hand by discussing the WML format.

Author Info:
By: Paul Bennett
Rating: 4 stars4 stars4 stars4 stars4 stars / 18
May 22, 2003
  1. · WAP for Fun and Profit - Part 1 - Basic WML Format
  2. · Summary

print this article

WAP for Fun and Profit - Part 1 - Basic WML Format
(Page 1 of 2 )

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

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">
<card id="card1" title="Basic WAP Page">
My first Wap page

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:
<a href="#anotherCard">Go to the next card</a>

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.

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">
<card id="card1" title="WML Post to server">
Pick your favourtite colour :
<select name="favColour">
<option value="red">red</option>
<option value="yellow">yellow</option>
<option value="pink">pink</option>
<option value="green">green</option>
<do type="accept" name="next" label="save">
<go href="processColour.php" method="post">
<postfield name="userColour" value="$(favColour)"/>

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.

blog comments powered by Disqus

- A New Toolbar Can Boost Your Web Site Traffi...
- Programming Custom Hardware for Windows
- Developing Embedded Systems - A Tools Introd...
- WAP for Fun and Profit - Part 1 - Basic WML ...
- HTTP Requesting with eVC++ 3.0 on Windows CE...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials