WAP: The Web for Cellphones and PDAs (3/4) - exploring XML | WebReference

WAP: The Web for Cellphones and PDAs (3/4) - exploring XML

WAP: The Web for Cellphones and PDAs

WML example

Let's look at a small example of WML code that contains some of the key features of WAP, as well as some telepathic capabilities of your WAP-enabled mobile phone:

<wml>
  <card id="FirstCard" title="Telepathy Demo">
    <p>Think of a secret number between 0 and 9</p>
    <do type="ACCEPT" label="Tell Me!">
      <go href="secret.xmls#getSecretNumber()" />
    </do>
  </card>
  <card id="SecondCard" title="Telepathy Result">
    <p>Your secret number was $(RESULT), right?</p>
  </card>
</wml>

This example contains a deck of two cards, FirstCard and SecondCard. The client displays the first card once the deck is received, in our case printing a message to make you think of a number between zero and nine, and then displaying a button that will tell you your number once you press it.

Two WML tags warrant a more detailed explanation:

The WML tag do

The do element gives the user a general mechanism for performing actions on the current card. The do element is mapped to a unique user interface element that the user can activate, such as a graphically rendered button, a soft key or function key, or a voice-activated command.

The type attribute indicates how the WML author intended the element to be used. Keep in mind that the author cannot rely on the particluar appearance and semantics of the widget used. Values for type are:

acceptPositive acknowledgement, acceptance
prevBack navigation through browser history list
helpContext-sensitive help
resetReset of state in WAP browser
optionsContext-sensitive selection from a list of options
deleteDeletion of item or choice

The WML tag go

The go element indicates a navigation to a specified URL. If the URL names a WML card or deck it is displayed. It pushes the current URL onto the browser history stack.

Once you activated the button the phone will tell you your secret number by executing the WMLScript below. How you activate the button depends on your particular phone. This is left to the device manufacturer as different devices have different sets and varying numbers of controls.

WMLScript example

The following script acompanies the WML deck above. It determines your secret number, sets the browser variable RESULT with its findings and selects the second card in the deck to display the result:

extern function getSecretNumber() {
  var r = Lang.random(9); 
  WMLBrowser.setVar("RESULT", r);
  WMLBrowser.go("secret.wml#SecondCard");
}

One characteristic of WAP is the different notions of script and browser variables. r is a script variable that only lives for the invocation of this function, whereas RESULT is a browser variable that is valid as long as the user stays on a particular WAP site. Browser variables can be inserted in WML as demonstrated in the SecondCard above, providing a simple templating mechanism.

My fellow Javascript columnist provides you with a more in-depth discussion of WML and WMLScript.

On to WAP Gateways and Browsers.

http://www.internet.com

Produced by Michael Claßen
All Rights Reserved. Legal Notices.

URL: http://www.webreference.com/xml/column12/3.html
Created: May 23, 2000
Revised: May 23, 2000