WAP - WML Syntax


Advertisements

The topmost layer in the WAP architecture is made up of WAE (Wireless Application Environment), which consists of WML and WML scripting language.

WML scripting language is used to design applications that are sent over wireless devices such as mobile phones. This language takes care of the small screen and the low bandwidth of transmission. WML is an application of XML, which is defined in a document-type definition.

WML pages are called decks. They are constructed as a set of cards, related to each other with links. When a WML page is accessed from a mobile phone, all the cards in the page are downloaded from the WAP server to mobile phone showing the content.

WML commands and syntaxes are used to show content and to navigate between the cards. Developers can use these commands to declare variables, format text, and show images on the mobile phone.

WAP Program Structure

A WML program is typically divided into two parts − the document prolog and the body. Consider the following code −

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN"
"http://www.wapforum.org/DTD/wml12.dtd">
<wml>
   <card>

   ...
   </card>
   ...more cards...
</wml>

The first line of this text says that this is an XML document and the version is 1.0. The second line selects the document type and gives the URL of the document type definition (DTD). This DTD gives the full XML definition of WML. The DTD referenced is defined in WAP 1.1, but this header changes with the versions of the WML. The header must be copied exactly so that the tool kits automatically generate this prolog.

The body is enclosed within a <wml>...</wml> tag pair as shown above. The body of a WML document can consist of one or more of the following −

  • Deck

  • Card

  • Content to be shown

  • Navigation instructions

WML Commands

The commands used in WML are summarized as follows −

Formatting

Command Description
<p> Paragraph
<b> Bold
<big> Large
<em> Emphasized
<I> Italicized
<small> Small
<strong> Strongly Emphasized
<u> Underlined
<br> Line Break

Inserting Images

<img src="image-path/image - name" alt="Picture not available" />

Using Tables

Command Description
<table> Definition of a table
<tr> Defining a row
<td> Defining a column
<Thead> Table header

Variables

Declared as −

<setvar name="x" value="xyz"/>

Used as −

$ identifier or
$ (identifier) or
$ (Identifier; conversion)

Forms

Command Description
<select> Define single or multiple list
<input> Input from user
<option> Defines an option in a selectable list
<fieldset> Defines a set of input fields
<optgroup> Defines an option group in a selectable list

Task Elements

Command Description
<go> Represents the action of switching to a new card
<noop> Says that nothing should be done
<prev> Represents the action of going back to the previous card
<refresh> Refreshes some specified card variables.

Events

The various events are as follows −

Command Description
<do> Defines a do event handler
<onevent> Defines an onevent event handler
<postfield> Defines a postfield event handler
<ontimer> Defines an ontimer event handler
<onenterforward> Defines an onenterforward handler
<onenterbackward> Defines an onenterbackward handler
<onpick> Defines an onpick event handler

Sample WML Program

Keep the following WML code into info.wml on your server. If your server is WAP enabled then you can access this page using any WAP device.

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN"
"http://www.wapforum.org/DTD/wml12.dtd">
<!-- WML prolog.declaration of file type and version>

<wml>
<!-- Declaration of the WML deck>
<card id="info" newcontext="true">
<!-- declaration of a card in deck>
<p align="center"><b>Information Center</b></p>
<!--paragraph declaration to display heading>
<p>
<!--paragraph declaration to display links>
<a href="Movie.wml">1. Movies info.</a>
<a href="Weather.wml">2. Weather Info.</a>
<!--declaration of links for weather and movies>
</p>
</card>
<!-- card end>
</wml>
<!-- program end>
Advertisements