Wmlexample - WML: Creating A WML Deck
Wmlexample - WML: Creating A WML Deck
In this example, we’ll start by creating a WML deck that allows us to first select a username
from a list, enter in a password, then have our selections repeated back to us. This will
illustrate the basic handling of user input, events, and variables all within one deck using
multiple cards.
Listing 1 - WMLExample.wml
<?xml version='1.0'?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
As you can see, the prolog of this document contains the XML version number to be used as
well as the Document Type Definition to be referenced. Following this comes the wml
document element (the deck) that contains three cards: Login, Password, and Results. Each
of these cards is defined using the element. Because the Login and Password cards also
define events, they use the element to define the event to be triggered. Figure 1 shows the
initial card loaded in a test browser.
Figure 1
When the "accept" type of the do element is encountered, it is displayed as an option on the
WAP device display (see Figures 2, 3, and 4).
Figure 2 Figure 3 Figure 4
If you are familiar with the anchor tag () in HTML, you know that it specifies an href
attribute that tells the browser where to link to if this anchor is selected. The WML element’s
"href" attribute works in the same manner. As with HTML, to link to another card in the
document, you simply prepend a # symbol before it. For example, to link to the Results
card, we define the following element:
<go href="#Results"/>
This Results card makes use of variables by retrieving and displaying the contents of the
name and password variables. Recall that variables are substituted into a card or deck by
using the following syntax:
$(variable_name)