WML - Syntax

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

Following is the basic structure of a WML program:

<?xml version="1.0"?>


<card id="one" title="First Card">
This is the first card in the deck


<card id="two" title="Second Card">
Ths is the second card in the deck


WML Document Prolog:

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). The DTD referenced is defined in WAP 1.2, 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 prolog components are not WML elements and they should not be closed, i.e. you should not give them an end tag or finish them with />.

WML Document Body:

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

  • Deck

  • Card

  • Content to be shown

  • Navigation instructions

Unlike HTML 4.01 Transitional, text cannot be enclosed directly in the <card>...</card> tag pair. So you need to put a content inside <p>...</p> as shown above.

Testing Your Program:

Put above code in a file called test.wml file, and put this WML file locally on your hard disk, then view it using an emulator.

This is by far the most efficient way of developing and testing WML files. Since your aim is, however, to develop a service that is going to be available to WAP phone users, you should upload your WML files onto a server once you have developed them locally and test them over a real Internet connection. As you start developing more complex WAP services, this is how you will identify and rectify performance problems, which could, if left alone, lose your site visitors.

In uploading the file test.wml to a server, you will be testing your WML emulator to see how it looks and behaves, and checking your Web server to see that it is set up correctly. Now start your emulator and use it to access the URL of test.wml. For example, the URL might look something like this:


NOTE: Before accessing any URL, make sure WAP Gateway Simulator is running on your PC.

When you will download your WAP program, then you will see only first card at your mobile. Following is the output of the above example on Nokia Mobile Browser 4.0. This mobile supports horizontal scrolling. You can see the text off the screen by pressing the "Left" or "Right" button.

WAP Example 1

When you press right button, then second card will be visible as follows:

WAP Example 2